Change WordPress user roles and capabilities Forums Restrict or Permit access inside WordPress – how to Limit role promotion, but maintain visibility of other roles.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #8132
    onedogsolutions
    Participant

    I saw the response here: https://wordpress.org/support/topic/user-promotion-limits/, but want to allow a role to see a role above them, with more capabilities, but not be able to promote to the roles above their current role.

    Here’s my current hierarchy:

    Board Member (can promote users)
    Coordinator (can promote users)
    Volunteer
    Adopter

    I’d like the Coordinator role to see the users in the Board Member role, but only be able to promote up to their current user role.

    No quite sure how to accomplish this.

    #8134
    Vladimir
    Keymaster

    You can exclude role ‘board_member’ from all user role selecting drop-down lists exactly for the user with role ‘coordinator’ using the code below:

    
    add_filter('editable_roles', 'ure_exclude_role', 10, 1);
    function ure_exclude_role( $roles ) {
        
        $user = wp_get_current_user();
        if ( empty( $user ) || empty( $user->roles ) ) {
            return $roles;
        }
        
        if ( !in_array( 'coordinator', $user->roles ) ) {
            return $roles;
        }
    
        // Remove board_member role from all dropdown user roles lists
        if ( isset( $roles['board_member'] ) ) {
             unset( $roles['board_member'] );
        }
    
        
        return $roles;
    }
    

    Also you can fully exclude roles and users with those roles from the point of view user with coordinator role with the help of “Other roles access” add-on:

    Other roles access management

    #8136
    onedogsolutions
    Participant

    Worked perfectly! Thank you!

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