Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #2121
    dweb360
    Participant

    Hello,

    How to hide “Other Roles” selectbox in “Additional Capabilities section” depending on user role?

    Thank you

    #2122
    Vladimir
    Keymaster

    Hi,

    ‘Other Roles’ section is shown, if this boolean filter ‘ure_show_additional_capabilities_section’ returns true (by default). It’s hidden in case this filter returns false.

    #3782
    RoxxiStudios
    Participant

    I have created a custom role based on administrator and am unable to hide the section in a user profile:

    Other Roles Select additional roles for this user

    I’d like to hide this from the custom role I’ve created, how can this be done?

    Any help is appreciated.

    Thank you!

    #3787
    Vladimir
    Keymaster

    Add this code to your active theme functions.php file or setup it as a Must Use plugin:

    
    add_filter('ure_show_additional_capabilities_section', 'ure_show_additional_capabilities_section');
    add_filter('ure_bulk_grant_roles', 'ure_show_additional_capabilities_section');
    
    function ure_show_additional_capabilities_section($show) {
        if (current_user_can('user-manager')) {
            $show = false;
        }
        
        return $show;
    }
    
    #3788
    RoxxiStudios
    Participant

    Thank you for the response, however, this had no effect.
    I’ll just accept it the way it is.

    I will say this, I don’t really see the value in having the ability to assign additional roles to a user. From my perspective, it is an option that could be removed from the plugin altogether – your call.

    Again, thanks for the response.

    #3789
    Vladimir
    Keymaster

    There are a lot of other users of User Role Editor which think different – they need multiple roles assignment to one user at WordPress. Historically, I developed this feature after I got multiple requests about it from plugins users.

    I will add a user interface for this option (swith ON/OFF other roles section) later.

    Currently it’s possible to manage this feature via filters, if your setup it correctly. This is a short demo video.

    Check if you don’t have any accident typos in a code and it’s really executed. For example, code above works for the user with ‘user-manager’ role only. Did you change a role ID for your own or may be remove role checking code?

    #7244
    ToiBox
    Participant

    Vladimir,

    Good day to you. I recently came across this very same issue and attempted the PHP snippet that you provided but did not have any luck. Upon closer reading, however, I see that you also mention to try and set the plugin as a MU-Plugin, which isn’t an option for me due to maintenance and update agreements on my client end. Should the above snippet still work, or, might you suggest something better so that I can turn this UI off within the WP backend? I’d like to keep this option away from my clients so that they do not get confused at both New User Registration and Edit User scenarios.

    Thank you.

    #7245
    Vladimir
    Keymaster

    While code version above work for the user with ‘user-manager’ role only, this version works for all users including one with ‘administrator’ role:

    
    add_filter('ure_show_additional_capabilities_section', 'ure_show_additional_capabilities_section');
    
    function ure_show_additional_capabilities_section( $show ) {
    
    /*  Remove comment if do not wish to apply this for administrators also  
        $lib = URE_Lib::get_instance();
        if ($lib->is_super_admin()) {
            return $show;
        }
    */            
        return false;
    }
    
    #7246
    ToiBox
    Participant

    Vladimir,

    Thank you, your solution worked out great.

    Much appreciated!

    #8501
    TWarrior
    Participant

    Hello,

    Congratulations on your plugin!

    Have you thought about adding this “Hide Other Roles control” as an option in the plugin settings?

    #8502
    Vladimir
    Keymaster

    Hi @TWarrior,

    Good suggestion. I will group similar recipes and add them as a separate settings section to the plugin options with one of the next update.

    #8503
    TWarrior
    Participant

    Hi Vladimir,

    Great!

    If we open in the wish list… there could also be the option to disable o hide “Grant Roles” button at Users list page:

    I usually have it deactivated with code:

    /*
    * Hides “Grant Roles” button at Users list page
    */
    add_filter(‘ure_bulk_grant_roles’, ‘ure_bulk_grant_roles’);
    function ure_bulk_grant_roles( $show ) {
    /* Remove comment if do not wish wish to apply this for administrators also
    $lib = URE_Lib::get_instance();
    if ($lib->is_super_admin()) {
    return $show;
    }
    */
    return false;
    }

    PD: The general idea behind all this is that I use your plugin to create a new role called “Manager”, with intermediate permissions between the Administrator and the Editor (something that surprises me a lot that does not come by default in WordPress).

    This is the role for people who “manage” the contents of the site and create new users of the site, but can not access the settings, plugins, etc..

    Thanks for your plugin!!!

    #8504
    Vladimir
    Keymaster

    OK. Thanks for sharing this.

    #8703
    RVSCC
    Participant

    Hi Vladimir

    Thank you for the code it removes the additional role option from the user profile page.

    But how can we disable this other role option complete?

    All our new user registrations are getting 2 roles by default
    1. the role from wp core (this we prefer)
    2. unmoderated role from user role pro plugin

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