I have a pretty specific requirement to show different text in a field label on the user profile page based on the current user’s role. I can’t seem to figure out how to check whether the current use is an “author”.
I am looking for a function like:
is_user_in_role($user, "author");
I imagine this is pretty simple, but I have searched for too long without an answer so I thought I would post it here.
If you only need this for current user current_user_can()
accepts both roles and capabilities.
UPDATE: Passing a role name to current_user_can()
is no longer guaranteed to work correctly (see #22624). Instead, you may wish to check user role:
$user = wp_get_current_user();
if ( in_array( 'author', (array) $user->roles ) ) {
//The user has the "author" role
}