多个用户的维护模式功能 - php数组无法正常工作?

I have created a maintenance mode function, but I can only get it to work for one username.

get_currentuserinfo();

global $current_user;

// MAINTAINANCE MODE
function website_site_maintenance() {
    global $current_user;
    if ( 'josh' != $current_user->user_login ) {
       // vars
       $logout_url = wp_login_url().'?mode=maintenance';
       wp_logout();
       wp_redirect( $logout_url, 302 );
    }     
}
add_action('get_header', 'website_site_maintenance');
add_action('admin_init', 'website_site_maintenance');


// CUSTOM LOGIN MESSAGES
function website_my_login_message() {

    if( $_GET['mode'] == 'maintenance' ){
        $message = '<p class="message"><b>Site undergoing maintenance.</b></p>';
        return $message;
    }

}
add_filter('login_message', 'website_my_login_message');

this above function works, but I want to add more maintenance users.

So i've tried this but it does not work...

// MAINTAINANCE MODE
function website_site_maintenance() {
    global $current_user;
    $maintenance_users = array('josh','george','bob');
    if ( $maintenance_users != $current_user->user_login ) {
       // vars
       $logout_url = wp_login_url().'?mode=maintenance';
       wp_logout();
       wp_redirect( $logout_url, 302 );
    }     
}

I simply tried to add the users into an array.

$maintenance_users = array('josh','george','bob');

But this doesn't seem to work as it should.

Instead of using

if ( $maintenance_users != $current_user->user_login ) {
   // vars
   $logout_url = wp_login_url().'?mode=maintenance';
   wp_logout();
   wp_redirect( $logout_url, 302 );
}

use

if ( !in_array($current_user->user_login, $maintenance_users) ) {
   // vars
   $logout_url = wp_login_url().'?mode=maintenance';
   wp_logout();
   wp_redirect( $logout_url, 302 );
}

The problem you're having is that you're comparing an array to a string, and this is not going to work. In the "correct" version you'll be checking whether the username of the currently logged in user is in the array $maintenance_users you specified. Hope that helps.