我将此添加到我的函数中。php通过将非管理员重定向到主页来限制对wp admin的非管理员访问。但是,这不适用于非用户(未登录的用户)。
如何在此脚本中包含非用户的访问者?
/**
* Restrict access to the administration screens.
*
* Only administrators will be allowed to access the admin screens,
* all other users will be automatically redirected to the front of
* the site instead.
*
* We do allow access for Ajax requests though, since these may be
* initiated from the front end of the site by non-admin users.
*/
function restrict_admin_with_redirect() {
if ( ! current_user_can( \'manage_options\' ) && ( ! wp_doing_ajax() ) ) {
wp_redirect( site_url() );
exit;
}
}
add_action( \'admin_init\', \'restrict_admin_with_redirect\', 1 );
FYI: I created a custom log-in form on a page other than wp-admin so this will not lock out admin
EDIT 2: this is in the functions.php file which may be complicating the issue since when a non-user accesses wp-admin, the server is treating that access as a failed log-in attempt and redirecting the user to the "access-denied" page and not a 404
/**
* Redirect user on invalid log-in attempts
*/
function login_failed() {
$login_page = home_url( \'/access-denied\' );
wp_redirect( $login_page . \'?login=failed\' );
exit;
}
add_action( \'wp_login_failed\', \'login_failed\' );
function verify_username_password( $user, $username, $password ) {
$login_page = home_url( \'/access-denied\' );
if( $username == "" || $password == "" ) {
wp_redirect( $login_page . "?login=empty" );
exit;
}
}
add_filter( \'authenticate\', \'verify_username_password\', 1, 3);