Add User Role Classes to the Admin Body
Adds classes such as role-editor to the admin body tag, so you can write CSS that hides or highlights things for specific roles.
Opens WPIDE on
Code
add_filter( 'admin_body_class', function ( $classes ) {
$user = wp_get_current_user();
foreach ( (array) $user->roles as $role ) {
$classes .= ' role-' . sanitize_html_class( $role );
}
return $classes;
} );
Notes
Example CSS: body.role-editor #menu-tools { display: none; }
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.