How to Hide the Adminstrator on the WordPress Users Screen

By michael  |  August 18th, 2009  |  Published in Blogging, WordPress  |  18 Comments

[update: you can now download this as a plugin. file at bottom of post]

WordPress has a great admin interface for managing just about every aspect of the software. One integral part of this interface is the “Authors & Users” screen:

WordPress Admin: Authors & Users

This is a great utility and it gives us,  as the developers, the freedom to let our clients have control over their own authors and users.

If you develop like we do though, you’ve probably learned that its better for everyone when we limit the clients ability to have access to areas of the site that they don’t need on a day to day basis. The Plugins and Appearance utilities are a great example.

This usually isn’t a problem because WordPress integrated role management into their software. A common solution – and one that we use at FullThrottle – is to simply retain the “Admintrator” role for yourself and split up the remaining roles for your client as needed. No problem!

What if we don’t want our clients to be distracted by the default “Administrator” account that we leave in tact though? Is there a simple way to remove this from the client’s screen? Well… if simple means fool proof and strictly using PHP and WordPress hook, then no (though we may submit some patches to make this possible). Regardless, what you can’t do with PHP, you can always do with jQuery. Below is our ‘smoke and mirrors’ way to remove all administrator level roles from the User’s screen if being viewed by anyone not in that role.

Removing Administrators from WordPress Users & Authors

All of the code below will be placed in your theme’s functions.php folder:

Step one: Queue the jQuery. Technically, jQuery should already be enqueued, but better safe than sorry:

// Enqueue jQuery
add_action('admin_enqueue_scripts' , 'ft_hide_administrator_jquery' );
function ft_hide_administrator_jquery(){
	global $pagenow;
	if ( 'users.php' == $pagenow ){
		wp_enqueue_script('jquery');
	}
}

Step Two: Remove ‘Administrator from the dropdown boxes

// Remove Administrator from "Editable Roles"
add_action( 'editable_roles' , 'ft_hide_adminstrator_editable_roles' );
function ft_hide_adminstrator_editable_roles( $roles ){
	if ( isset( $roles['administrator'] ) && !current_user_can('level_10') ){
		unset( $roles['administrator'] );
	}
	return $roles;
}

Step Three: Use some jQuery magic to remove the administrator

// Hide Administrator from list of users
add_action('admin_head' , 'ft_hide_administrator_user');
function ft_hide_administrator_user(){
	if ( !current_user_can('level_10') ){
		?>
		<script type='text/javascript' >
			jQuery(document).ready(function(){
                          var admin_count;
                          var total_count;

			  jQuery("#list-filter > .subsubsub > li > a:contains(Administrator)").each(function(){
			  	admin_count = jQuery(this).children('.count').text();
				admin_count = admin_count.substring(1, admin_count.length - 1);
			  });
                          jQuery("#list-filter > .subsubsub > li > a:contains(Administrator)").parent().remove();
			  jQuery("#list-filter > .subsubsub > li > a:contains(All)").each(function(){
			  	total_count = jQuery(this).children('.count').text();
				total_count = total_count.substring(1, total_count.length - 1) - admin_count;
				jQuery(this).children('.count').text('('+total_count+')');
			  });
			  jQuery("#users > tr .administrator").parent().parent().remove();
			});
		</script>
		<?php
	}
}

That’s it! As always, if you find any bugs or have any suggestions, just leave a comment. Below is a link to download the whole chunk of code. Just paste the contents into functions.php and you should be good to go!

Download Code:

Final Result:

Final Results

Responses

  1. Posts about plugins as of August 18, 2009 | All About WordPress says:

    August 18th, 2009 at 7:01 pm (#)

    […] How to Hide the Adminstrator on the WordPress Users Screen […]

  2. uwiuw says:

    November 12th, 2009 at 1:26 am (#)

    is it possible to hide it complety ? especillay when javascript disable ? i want user can not see who is the admin.

  3. Ade says:

    January 24th, 2010 at 2:06 pm (#)

    I installed plugin successfully but when i activate it says The plugin does not have a valid header.

    what can i do

  4. Jason says:

    January 29th, 2010 at 9:23 am (#)

    The plugin is wonderful to have. However, there’s a small problem if the non-admin user happens to be an expert with WP.

    In Admin >> Authors & Users, any Admins will not be displayed. But one can change one of the User Profile edit links from (say user_id=3):
    http://www.mysite.com/wp-admin/user-edit.php?user_id=3&wp_http_referer=%2Fwp-admin%2Fusers.php

    to, user_id=1 (which is Admin):
    http://www.mysite.com/wp-admin/user-edit.php?user_id=1&wp_http_referer=%2Fwp-admin%2Fusers.php

    That link will load up, and can directly edit the Admin’s profile. Is there a way to make this plugin “bullet proof”?

    Thank you.

  5. Vladimir says:

    April 3rd, 2010 at 5:14 pm (#)

    Hi!

    Thank you for the nice and original decision. I plan to use this idea and jQuery code in my User Role Editor WordPress plugin. As gratitude for your help, I will include this page link to the Greetings section of my plugin.

    Regards,
    Vladimir.

  6. Charles Potel says:

    May 18th, 2010 at 1:22 pm (#)

    Hello! Very cool the initiative to create a way to hide the admin user, this is very good at creating websites with a custom administrative area as well, only that the system did not work on my WordPress! I tried using the functions.php file and installing the plugin and even then the user Admin keeps appearing for other users! What could it be? (E.. Excuse my English because I am still learning)

  7. Jacob says:

    June 29th, 2011 at 1:48 am (#)

    Will this work as a ‘must use’ plugin? Doesn’t seem to for me

  8. queeneve says:

    July 3rd, 2011 at 1:19 pm (#)

    great plugin , you solved my problem dear with this plugin
    thanks a punch

  9. Philemon says:

    July 19th, 2011 at 12:54 pm (#)

    May you please post an explanation with video because this plugin is s importanot for expert wordpress users

  10. André says:

    October 19th, 2011 at 12:35 pm (#)

    Excelent tutorial.

    I´ve made a wordpress plug-in based on this tutorial at my site.

    The plug-in has an admin page that provides users to hide certain roles from non administrator users.

    Check it out at http://lelis718.com.br/softchill/geral/2011/10/wordpress-de-clientes/

    Thanks!

  11. Joo says:

    October 20th, 2011 at 4:05 am (#)

    Hello,
    it seems that the plugin does not work in WP 3.2.1 – admin users are still listed.
    With best regars, Joo

  12. albert says:

    January 30th, 2012 at 3:32 pm (#)

    Hi!

    I installed your plugin, but admin is still showning in users with edithor role, in users section…

    using wp3.3

    any help?

  13. Stefan says:

    May 11th, 2012 at 5:31 am (#)

    Is not working on 3.2.2.

    JQuery is loaded but the filter doesn’t apply.
    I need to filter out 1 user of the complete list. How can I archive that?

  14. yudi eko says:

    May 30th, 2012 at 4:24 am (#)

    I have try it on WP 3.3.2 it don’t work..do you have the newest version?

    thanks a lot

  15. web_dev says:

    August 3rd, 2012 at 3:54 pm (#)

    Hey thanks for this part especially: “Step Two: Remove ‘Administrator from the dropdown boxes.” I’ve been trying to do that for hours (even the WordPress docs aren’t helpful here) and your example did the trick.

  16. Allan says:

    August 4th, 2012 at 10:11 pm (#)

    Hi,

    This is a nice plugin however I can’t get it to work on WP version 3.4.1. Is there an update for this?

  17. Happy says:

    October 29th, 2012 at 12:41 am (#)

    I plugged this into the functions.php, and the first part worked (removed administrator from drop down menu), but the second part does not seem to work (removing admins from user status less than admin). Any idea why this would not work? Thanks.

  18. marisa says:

    January 7th, 2013 at 10:43 am (#)

    I installed this plugin and nothing happened. I don’t know why.