similar to Editor can create any new user except administrator

I have set up a WP multi-site with custom roles. One of the roles can add users. I need a solution to only show two roles available to the limited role on add user and leave all user types available to administrator. This code snipped works great for removing Administrator mode, but I don’t understand enough of it to know if I could expand it to exclude other roles as well. Any help appreciated.

Related posts

Leave a Reply

1 comment

  1. Simple all you need to do is edit this part of the code :

    function editable_roles( $roles ){
        if( isset( $roles['administrator'] ) && !current_user_can('administrator') ){
          unset( $roles['administrator']);
        }
        return $roles;
      }
    

    and change it to

    function editable_roles( $roles ){
        //don't change anything if current user is admin 
        if (current_user_can('administrator')) {
            return;
        }else{
            if( isset( $roles['administrator'] ) && !current_user_can('administrator') ){
               unset( $roles['administrator']);
               //here you add  "unset( $roles['role_to_remove']);" for each role you wish to remove
            }
        return $roles; 
      }