Lock out all WordPress Administrators except two specific users
I used the snippet below to lock out all administrators and editors except myself
if ( is_user_logged_in() ){
$current_user = wp_get_current_user() ;
if ( in_array( 'administrator', (array) $current_user-roles ) || in_array( 'editor', (array) $current_user-roles )) {
if ($current_user-user_login != 'sheila' ){
wp_logout();
return new WP_Error( 'login_again_please', 'Please log in again' );
}
}
}
When I try to add a second user in the second if statement we are both locked out:
if ( is_user_logged_in() ){
$current_user = wp_get_current_user() ;
if ( in_array( 'administrator', (array) $current_user-roles ) || in_array( 'editor', (array) $current_user-roles )) {
if (($current_user-user_login != 'john' ) || ($current_user-user_login != 'sheila' )){
wp_logout();
return new WP_Error( 'login_again_please', 'Please log in again' );
}
}
}
How do I fix the above snippet to allow two administrators/editors with specific usernames to login or can I have an alternative with the same outcome?