Displaying which Role the current user is assigned to

Is there a section on the admin panel of my WordPress installation which just displays what role the current logged in user has?

For example, I know I have administrator permissions because I know that but I can’t see it confirmed anywhere.

Also, if I set myself up as an Editor, how do I quickly check I am definitely logged in as an Editor? (apart from just “knowing”).

It would be really nice just to know that in case you’re doing 10 things at once and lose track.

Maybe it would be nice to display that after the “How are you..” in the top right.

EDIT

Before anyone jumps in and mentions the Users panel. Yes, I can see there is the Role column (as I am an admin), but someone who was just a Contributor wouldn’t be able to see that, right?

3 Answers
3

As you suggested, here’s how you can display the roles next to the username in the admin bar:

function wpse_203917_admin_bar_menu( $wp_admin_bar ) {
    if ( ! $node = $wp_admin_bar->get_node( 'my-account' ) )
        return;

    $roles = wp_get_current_user()->roles;

    $node->title .= sprintf( ' (%s)', implode( ', ', $roles ) );

    $wp_admin_bar->add_node( $node );
}

add_action( 'admin_bar_menu', 'wpse_203917_admin_bar_menu' );

Leave a Comment