Change WordPress user roles and capabilities › Forums › How to or FAQ › Remove superadmin role from the “change role to” menu in user listing
Tagged: Hide super admin, User role listing
- This topic has 13 replies, 2 voices, and was last updated 7 years, 5 months ago by pyushika.
-
AuthorPosts
-
22/07/2017 at 10:10 #4006pyushikaParticipant
In my multi-site network, I am using “User Role Editor Pro” plugin to assign capabilities to roles. I want the site-admins (administrators) of sub-sites to have capability to change role of any user to any other role except to super-admin role. The only way to achieve that, as per my limited understanding, is to hide the super-admin role from the options of “change role to” menu on the user listing page.
How can I hide the option of Superadmin in “change role to” menu in user listing? Or else, is there any better way to do that using your plugin?
Thanks & Regards!
22/07/2017 at 10:22 #4007VladimirKeymasterWordPress built-in ‘administrator’ role is hidden from any drop-down list for single site administrators (without superadmin privilege) by default.
If you wish to exclude another role(s) from access of user with ‘list_users’, ‘edit_users’ capabilities you can use “Block other roles access” add-on.
22/07/2017 at 17:11 #4008pyushikaParticipantWordPress built-in ‘administrator’ role is hidden from any drop-down list for single site administrators (without superadmin privilege) by default.
That’s good. But my problem is other way around. Users with ‘administrator’ role are capable of assigning superadmin role to self or to others.
If you wish to exclude another role(s) from access of user with ‘list_users’, ‘edit_users’ capabilities you can use “Block other roles access” add-on.
Thanks for pointing out this another wonderful feature of the plugin. I, however, failed to achieve what I need to even after trying this feature. Superadmin role is not being hidden from users having ‘administrator’ role. I, however, have created another role equivalent to ‘administrator’ role by copying its capabilities (and assigning few more) and superadmin role is being hidden from this new role.
May be I’m doing something wrong. Can you please look into it to point out what should I be doing to hide superadmin roles from users having administartor role?
Thanks!
23/07/2017 at 00:51 #4009VladimirKeymasterCan you show the screeshots what critical role is available to users with ‘administrator’ role, but should not be?
What do you name ‘superadmin’ role?
Did you allow to single site admin access to the network admin like manage_network_options, manage_network_users?23/07/2017 at 05:13 #4010pyushikaParticipant1. There is no network admin options assigned to administrator role (which I have named as Site Admin).
2. Other Roles for administrator (Site Admin) is as in following image.
3. “Change role to” options available for administrator (Site Admin) are as shown in following image. Please notice the Super Admin (super_admin) role available as an option which I don’t want.
4. Name of super-admin role is Super Admin as shown in following image:
5. “Change role to” options available for super_admin (Super Admin) are as shown in following image. Please notice the Super Admin (super_admin) and Site Admin (administrator) roles are not available as an option which as desired.
6. Schoolers Admin (schoolers_admin) is another role copied from administrator role and assigned some extra capabilities.
7. “Change role to” options available for schoolers_admin (Schoolers Admin) are as shown in following image. Please notice the Super Admin (super_admin) and Site Admin (administrator) roles are not available as an option which as desired.
Thus, “Change role to” options are NOT as expected for administrator role only.
Please help!
Thanks!
23/07/2017 at 09:43 #4011VladimirKeymasterThank you for details. One more thing to check, just to be sure:
Login as superadmin, go to “Network Admin -> Users” and check if your test user with ‘administrator’ role does not have ‘Superadmin’ privilege granted there.
It could be a reason why ‘Other roles access’ does not work for ‘Site admin (administrator)’ role.23/07/2017 at 10:26 #4012pyushikaParticipant23/07/2017 at 14:15 #4013VladimirKeymasterThanks for all details which helped to reproduce an issue.
Sorry for delay with a solution. I re-tested a similar configuration, got the same result and reviewed my code after that. ‘Other roles access’ add-on restrictions are not applied for single site admins (administrator) role under multisite by default. But it’s possible to change this with a custom filter:add_filter('ure_not_block_other_roles_for_local_admin','ure_not_block_other_roles_for_local_admin'); function ure_not_block_other_roles_for_local_admin($flag) { return false; }
23/07/2017 at 15:50 #4014pyushikaParticipantThanks for following up with the issue and providing a solution. I’m, however, not sure how to use it. I think this code will not go into functions.php because different sites are using different child theme (though currently of same parent theme).
Or, are you going to release an update sometimes soon? I can wait for few days.
Thanks!
23/07/2017 at 15:58 #4015VladimirKeymasterIf you wish to change a default behavior of User Role Editor independently from a theme you can setup this code as a Must Use plugin.
Create a .php file, start it from < sign on the 1st row. Copy/paste a code there. Place that file to wp-content/mu-plugins folder. That’s it.23/07/2017 at 16:35 #4016pyushikaParticipantThanks! But, it seems, there is a mistake in above code: both the arguments of add_filter() function are same.
Just now I stumbled upon a post where you have provided solution for a similar case. Here is the link. This post raises some doubt for me. Which code should I use? Also, is it sure that it will not be addressed in any of future updates? Will my mu-plugin not interfere with any such update in future.
Thanks!
24/07/2017 at 01:18 #4017VladimirKeymasterYes, it’s the same solution. I just changed a name of a custom function which returns FALSE in order to it would correspond to the what it really does. There is no bug in a code I offered above. I tested it before to send to you. Both version of code work. You can use anyone. Or even this 3rd version:
add_filter('ure_not_block_other_roles_for_local_admin','my_not_block_other_roles_for_local_admin'); function my_not_block_other_roles_for_local_admin($flag) { return false; }
This custom filter included into Pro version code and will be there. The only thing which I can make for this point in future – add the checkbox to the URE Pro settings. But anyway its value will be sent to an existing filter
'ure_not_block_other_roles_for_local_admin'
instead of default TRUE, which is sent currently.I plan in future to add custom filters for all options of URE Settings in order URE Pro user can configure all URE functionality seting up a .php file as a must use plugin.
24/07/2017 at 02:35 #4022VladimirKeymasterI added the information about this filter to the end of “Other roles access” add-on documentation page.
24/07/2017 at 13:44 #4026pyushikaParticipantIt’s working beautifully; thank you very much!
You were so prompt in your replies that sometimes it felt like we were chatting. Much appreciated!
🙂Regards!
-
AuthorPosts
- You must be logged in to reply to this topic.