The question might be simple. Since I need to fix it soon I had to ask.

Currently I am modifying a free plugin. In that I am having the user login string.

How can I get the role for that login?

I'm using WordPress 3.8.


You'll want to use get_user_by(), which will return a WP_USER object which contains roles and capabilities. More info here.

$user = get_user_by( 'login', 'username');

$roles = $user->roles // this will contain an array of the roles the user is in

You can use the get_user_by() function.


Get all the roles assigned to the user John Smith, that uses the login johnsmith:

$user = get_user_by( 'login', 'johnsmith' );
print_r( $user->roles );

This might give you the following output:

Array ( [0] => author )
  • 1
    This is also fine. But not able to upvote because of my low points. Thank you..:) – Kannan Ramamoorthy Jan 16 '14 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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