• I have “innovation_team_admin” custom role in my site, which has to have permision to change roles for other users. I gave this role capabality of ‘edit_users’, but I don’t want that this user can add ‘administator’ cpabality for other users.

    I’ve tried:

    add_action( 'set_user_role',  'changeUserRole', 10, 3 );
    
    function changeUserRole($user_id, $role, $old_roles){
              $current_user_role = wp_get_current_user()->roles[0];
    
              if($current_user_role === self::INNOVATION_TEAM_ADMIN) {
                if($role === 'administrator')
                  $role = $old_roles[0];
              }
              return $role;
            }

    but it’s not working.

  • The topic ‘How to use set_user_role action to restrict role setting for certain roles’ is closed to new replies.