Hide the Administrator Role From Non-Administrators
Removes Administrator from the role dropdowns for anyone who is not an administrator, so delegated user managers cannot promote themselves or others.
Opens WPIDE on
Code
add_filter( 'editable_roles', function ( $roles ) {
if ( ! current_user_can( 'manage_options' ) ) {
unset( $roles['administrator'] );
}
return $roles;
} );
Notes
Useful whenever you give a non-administrator the ability to manage users.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.