hide one or more admin accounts from all other roles/users

[ad_1]

Hi @nreljed

You can use role level so other user can’t edit higher level role => https://publishpress.com/knowledge-base/how-to-block-wordpress-users-from-creating-higher-level-users/

Thread Starter
neosan

(@nreljed)

Hello @rizaardiyanto and happy new year
I managed to make the code work I had not copied and pasted well

//* Hide this administrator account from the users list
add_action('pre_user_query','site_pre_user_query');
function site_pre_user_query($user_search) {
	global $current_user;
	$username = $current_user->user_login;
 
	if ($username == 'admin') {
	}
 
	else {
	global $wpdb;
    $user_search->query_where = str_replace('WHERE 1=1',
      "WHERE 1=1 AND {$wpdb->users}.user_login != 'admin'",$user_search->query_where);
  }
}

//* Show number of admins minus 1
add_filter("views_users", "site_list_table_views");
function site_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="https://projectdmc.org/support/topic/hide-one-or-more-admin-accounts-from-all-other-roles-users/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;
}

but that does not change the fact that it will be great if it was supported directly in a scenario where we would like for example to also hide editor and admin roles from authors etc.
in your link it talks about publishpres Permissions things that I don’t understand since capabilities already does by default what I want, my client role editor does not have the right to create higher roles or admin.
we would ideally just to allow this kind of hide in capabilities directly in the plugin . since it already does what Permissions does

it would be counter-productive and illogical to install two plugins to perform this single action
publishpress capabilities replaces my ex role editor plugin very well, he just need more.. Capabilities 🙂

  • This reply was modified 40 minutes ago by neosan.

Thank you for your suggestion!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer