Get User Roles In WordPress

$user = get_userdata( $user->ID );
$capabilities = $user->{$wpdb->prefix . 'capabilities'};

if ( !isset( $wp_roles ) )
$wp_roles = new WP_Roles();

foreach ( $wp_roles->role_names as $role => $name ) {

if ( array_key_exists( $role, $capabilities ) )
echo $role;
}

1 Comment

You must be logged in to post a comment.


  1. Sweet, definitely gonna need this one soon. I saw it had an extra re-tweet on it. Wonder who did that?