Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get user role in WordPress
* Get user's role
* If $user parameter is not provided, returns the current user's role.
* Only returns the user's first role, even if they have more than one.
* Returns false on failure.
* @param mixed $user User ID or object.
* @return string|bool The User's role, or false on failure.
function km_get_user_role( $user = null ) {
$user = $user ? new WP_User( $user ) : wp_get_current_user();
return $user->roles ? $user->roles[0] : false;

This comment has been minimized.

Copy link

commented Jul 5, 2017

Very handy. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.