How to target with css, admin elements according to user role level?

The admin_body_class filter lets you add classes to the body tag.

This function will add all roles as classes in the form role-$role, for example role-administrator, to the body tag:

function wpa66834_role_admin_body_class( $classes ) {
    global $current_user;
    foreach( $current_user->roles as $role )
        $classes .= ' role-' . $role;
    return trim( $classes );
}
add_filter( 'admin_body_class', 'wpa66834_role_admin_body_class' );

Leave a Comment