4

I am using plugins "Capability Manager Enhanced" and "Adminimize". Between these two I have been able to do much of what I want to do.

There are still some elements I need to hide and have been able to target them with css.

The problem is that these elements are hidden across all admin user levels.

Is there something built in that distinguishes the different role levels in the admin?

I would think the best way to do this would be to add a class to the body tag according to the role level at log-in -- such as "author" class if log-in role level is "author".

If this is the best way I wouldn't know how to write the code to do this. I assume it would be a php addition to function.php. ???

1 Answer 1

5

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' );
1
  • I got a bit lost between your code, the WordPress Code Reference page and the note there. Is your code still the best approach? If so, could you please add an example to your answer e.g. using #wp-version to hide the WordPress version found on the bottom of At a Glance box of the Dashboard for all contributors and authors (two roles)? Sep 30, 2016 at 6:35

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.