Change WordPress user roles and capabilities Forums How to or FAQ Remove superadmin role from the “change role to” menu in user listing

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #4006
    pyushika
    Participant

    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!

    #4007
    Vladimir
    Keymaster

    WordPress 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.

    #4008
    pyushika
    Participant

    WordPress 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!

    #4009
    Vladimir
    Keymaster

    Can 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?

    #4010
    pyushika
    Participant

    1. There is no network admin options assigned to administrator role (which I have named as Site Admin).

    Image and video hosting by TinyPic

    2. Other Roles for administrator (Site Admin) is as in following image.

    Image and video hosting by TinyPic

    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.

    Image and video hosting by TinyPic

    4. Name of super-admin role is Super Admin as shown in following image:

    Image and video hosting by TinyPic

    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.

    Image and video hosting by TinyPic

    6. Schoolers Admin (schoolers_admin) is another role copied from administrator role and assigned some extra capabilities.

    Image and video hosting by TinyPic

    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.

    Image and video hosting by TinyPic

    Thus, “Change role to” options are NOT as expected for administrator role only.

    Please help!

    Thanks!

    #4011
    Vladimir
    Keymaster

    Thank 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.

    #4012
    pyushika
    Participant

    No, our test user ‘andy’ has no superadmin privileges even there. Please see following screen shot.

    Image and video hosting by TinyPic

    #4013
    Vladimir
    Keymaster

    Thanks 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;
    }
    
    #4014
    pyushika
    Participant

    Thanks 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!

    #4015
    Vladimir
    Keymaster

    If 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.

    #4016
    pyushika
    Participant

    Thanks! 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!

    #4017
    Vladimir
    Keymaster

    Yes, 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.

    #4022
    Vladimir
    Keymaster

    I added the information about this filter to the end of “Other roles access” add-on documentation page.

    #4026
    pyushika
    Participant

    It’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!

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.