Ready to get started?Download WordPress


[resolved] Getting a WP user's role (5 posts)

  1. ninnypants
    Posted 5 years ago #

    I need to retrieve a users role for some functionality in my site, but cannot find a way to get the role.
    I've tried get_currentuserinfo() but have had no luck with that. Is there another way to retrieve this information?

  2. ClaytonJames
    Posted 5 years ago #

    Something like...

    <?php if (current_user_can('****_****')){ ?>

    ...followed by conditional statements maybe? I'm not sure if that's on the right track or not ('cause I'm just a hack)!


    list of capabilities and rolls found here

  3. ninnypants
    Posted 5 years ago #

    Works thanks!
    I was hoping for something simpler, but this seems to be the only way.

  4. jaredstein
    Posted 5 years ago #

    Using WP_User class is easier. First, grab the user info:
    $user = new WP_User($ID);

    Now you can grab the wp_capabilities array and do what you want with it.

    E.g. test for a role capability:

    if ($user->wp_capabilities['administrator']==1) {

    E.g. print a list of user's roles as an array:


    Details on WP_user:

  5. Capn Code
    Posted 5 years ago #

    Yet another method:

    global $current_user;


    if($current_user->user_level == 0){ /* Is user subscriber? */

    *See: User Level to Role Conversion to set appropriate value for user_level.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.