I have a custom log-in form on a custom page that handles all logging in/out. The form posts to wp-login.php as required.
<form name="loginform-custom" id="loginform-custom" action="http://localhost/wp-login.php" method="post">
All invalid log-in attempts are handled by this following script in the functions.php file:
/**
* Redirect user on invalid log-in attempts
*/
function login_failed() {
wp_redirect( home_url('/access-denied') );
exit;
}
add_action( 'wp_login_failed', 'login_failed' );
function verify_username_password( $user, $username, $password ) {
if( $username == "" || $password == "" ) {
wp_redirect( home_url('/access-denied') );
exit;
}
}
And I use the following script in my functions.php file to redirect all non-admins away from wp-admin to a 404 page.
function restrict_admin_with_redirect() {
if ( ! current_user_can( 'manage_options' ) && ( ! wp_doing_ajax() ) ) {
wp_redirect( site_url('/404') );
exit;
}
}
add_action( 'admin_init', 'restrict_admin_with_redirect', 1 );
However, here is my problem. When non-users (random visitors) try to access wp-admin, they are taken to the access denied page despite the redirect script to 404. For some reason, whenever anybody tries to access wp-admin, the server treats it as a log-in attempt and when they are (of course) denied log-in, they are redirected to the access denied page.
Is there any way I can force a 404 when wp-admin is accessed by a user? Also, I'd like a true 404 and not a redirect to a 404 page (which is not a true 404).
Thoughts?
Is there a way to force anyone (users and non-users) to a 404 when they try to access wp-admin? In the action script above, even if I redirect non-admins to a 404.php page, non-users still get sent to the standard access d