Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers

up vote 9 down vote accepted

If you only need this for current user current_user_can() accepts both roles and capabilities.

share|improve this answer
Wow. Thank you. That is exactly what I need. I saw that function elsewhere, but failed to realize that you could pass in a role name. You Rock! – jessegavin Dec 8 '10 at 16:08

I was looking for a way to get a user's role using the user's id. Here is what I came up with:

function wp_get_user_roles_by_user_id( $user_id ) {
    $user = get_userdata( $user_id );
    return empty( $user ) ? array() : $user->roles;
}
share|improve this answer
works fine for me to get the first role assigned to a user. – QL Studio Oct 10 '12 at 19:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.