I have set up a WordPress site for a client. The client has the Editor role, however I have installed the Members plugin and given the client the capability to add new users to the WP admin. This is working just fine.
The question I have is that I would like for the client to have the ability to create new user as with the roles of a Contributor, Subscriber, Editor and Author, but NOT Administrator. The new users the client creates should not have the Administrator role. Is it possible to hide this option somehow?
Thanks
Vayu
It’s actually pretty easy. You need to filter into
map_meta_caps
and stop editors from creating/editing admins, and remove the administrator role from the ‘editable roles’ array. This class, as a plugin or in your theme’s functions.php file would do it:EDIT
Ok, so I took a look into why it was letting user deletion slip through. It looks like delete_user is handled slightly differently from edit_user; I’ve modified the map_meta_cap method to work around this. I’ve tested on 3.0.3 and this will prevent anybody but administrators from actually deleting, editing, or creating an administrator.
EDIT 2
I updated the code to reflect @bugnumber9 ‘s answer below. Please go give that answer an upvote!
Despite of being ~7 years old, this thread can be googled easily and still provides a working solution. I mean the code provided by @John P Bloch.
That said, under PHP 7 it produces a non-critical error (PHP Deprecated) as follows:
In order to fix this simply replace this piece:
with this:
This will fix the problem.
I was looking for a solution where the Editor could edit only menus AND create/edit users without needing a plugin. So I ended up making it for those who are interested.
@John P Blochs solution still works fine, but I thought I would throw in my little filter for ‘map_meta_cap’ as well. Just a little shorter and cleaner, at least for my eyes 😉