6

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.

2
  • 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! Mar 13, 2018 at 19:30
  • 1
    @DaveRomsey Done!
    – twelvell
    Mar 13, 2018 at 19:36

1 Answer 1

7

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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