4

I have to hide Administrator user role in the "User roles" area for these pages:

  • /wp-admin/users.php
  • /wp-admin/user-new.php
  • /wp-admin/user-edit.php

New user

I would like to hide this role option for other users that have an ability to select the Administrator role in order to prevent anyone other to give admin rights.

  • Glad you solved the issue! Please post your solution as an answer to your question, then stop back in a few days and click the checkmark to accept it. This helps keep the site tidy and makes your answer more visible to future visitors looking to solve the same problem. Thank you! – Dave Romsey Mar 13 '18 at 19:30
  • 1
    @DaveRomsey Done! – twelvell Mar 13 '18 at 19:36
6

SOLUTION:

// 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'] );
    }
    return $roles;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.