Change WordPress user roles and capabilities Forums Restrict or Permit access inside WordPress – how to How can i hide Other Roles dropdown menu from user editor, Grant Role button…

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #4681
    Fotini Kokkinos
    Participant

    Hello!
    I searched this forum and I found the following function but it doesn’t work for me:
    ————————
    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;
    }
    ——————————
    I want to hide the Other Roles dropdown menu from user editor for specific Roles.

    Additionally I want to hide the “Grant Role” button for specific roles, but I didn’t find any relative thread in this forum that is applicable to my case.

    Finally, I want to hide the “View” action from the Users list because I have completely ristricted any Frontend view for all the users of all the roles.

    Your help is really appreciated!

    #4682
    Vladimir
    Keymaster

    Hi Fotini,

    Code above works for the user with ‘user-manager’ role only. Replace ‘user-manager’ with your own role ID or check if your user really has ‘user-manager’ role.

    #4683
    Vladimir
    Keymaster

    This code hides ‘View’ actions at Users list from all user except user with ‘administrator’ role:

    
    add_filter('user_row_actions', 'hide_users_view_action', 10, 1);
    function hide_users_view_action($actions) {
        
        if (current_user_can('administrator')) {
            return $actions;
        }
        
        if (isset($actions['view'])) {
            unset($actions['view']);
        }
        
        return $actions;
    
    }
    
    #4686
    Fotini Kokkinos
    Participant

    Thank you so much for your code snippets.They worked just fine!

    What about the “Grant Roles” button? How can I hide it too from certain roles?

    Thank again!

    #4687
    Vladimir
    Keymaster

    Code, which you showed above, should work for the users with right role. Let me know if you still have difficulties with it after checking a role ID.

    It’s possible to use ‘ure_bulk_grant_roles’ filter. Return false with it to hide “Grant Roles” button. This is a quote from the URE source code:

    
     $bulk_grant_roles = apply_filters('ure_bulk_grant_roles', true);
     if ($bulk_grant_roles) {
         new URE_Grant_Roles();
     }
    
    #4688
    Fotini Kokkinos
    Participant

    Hello!

    I have the followng code that works fine for hiding the “Other Roles” dropdown field fro the User’s Editor screen. This snippet, doesn’t affect the “Grant Roles” Button.
    //Hide “other roles” from user editor//
    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(‘comapny_editor’)) {
    $show = false;
    }

    return $show;
    }

    I tried the new snippet you gave me, with “False” but the button is till there….

    Pls see the screenshot
    http://nimb.ws/oKGmaE

    #4689
    Fotini Kokkinos
    Participant

    Hello!
    Is there any solution finally for hiding the “Grant Roles” button or the whole “Grant Role” feauter for specific user roles?

    or else,

    How can I completely disable this plugin’s feature?

    Pls advice.

    #4690
    Vladimir
    Keymaster

    Hi,

    1) Quick workaround. Open user-role-editor-pro/includes/classes/user-role-editor.php and comment line #193
    Code will look like:

    
            $bulk_grant_roles = apply_filters('ure_bulk_grant_roles', true);
            if ($bulk_grant_roles) {
    //            new URE_Grant_Roles();
            }
    

    This change will be lost after every update to a new version.

    2) Needs some time and PHP developer experience – find why you can not set false via ‘ure_bulk_grant_roles’ filter.

    #4691
    Fotini Kokkinos
    Participant

    T H A N K Y O U!!!
    This one worked!

    #5310
    whitenoise
    Participant

    Perfect! I’ve added this code and it works great 🙂

    #5311
    whitenoise
    Participant

    Also I wanted to remove some (but not all) of the roles from the ‘Role’ box on the new user screen. I came across this code:

    // Remove Administrator role from roles list
    add_action( 'editable_roles' , 'hide_adminstrator_editable_roles' );
    function hide_adminstrator_editable_roles( $roles ){
        if ( isset( $roles['administrator'] ) && !current_user_can('level_10') ){
            unset( $roles['administrator'] );
            // add more unset rules here for your user roles
        }
        return $roles;
    }

    Which does the job perfectly if it helps anyone else.

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