I am trying to get this code working so I can list a set of usernames that are not allowed to see updates in the Wordpress admin panel. Right now it only works with a single username. Is there a way to set this up as an array so that I can list multiple usernames? Kind of something like:

 if($user && isset($user->user_login) && array('username', 'username2') == $user->user_login

Here is the current code that works for just one username:

function disable_wp_updates() {
    global $wp_version;
    return (object) array( 'last_checked' => time(), 'version_checked' => $wp_version, );
add_action('admin_init', 'check_wp_username');
function check_wp_username()
    $user = wp_get_current_user();
    if($user && isset($user->user_login) && 'username' == $user->user_login ) {
        // do stuff
        add_filter( 'pre_site_transient_update_core', 'disable_wp_updates' );     // Disable WordPress core updates
        add_filter( 'pre_site_transient_update_plugins', 'disable_wp_updates' );  // Disable WordPress plugin updates
        add_filter( 'pre_site_transient_update_themes', 'disable_wp_updates' );   // Disable WordPress theme updates
    // remove the update count number:
        global $menu,$submenu;
        $menu[65][0] = 'Plugins';   
        $submenu['index.php'][10][0] = 'Updates';   



So right now you have this

if ($user && isset($user->user_login) && 'username' == $user->user_login ) {

To check for one specific user. If you want to check against multiple usernames, PHP's function in_array() comes in handy

$allowed = array(
if ($user && isset($user->user_login) && in_array($user->user_login, $allowed) ) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.