Skip to content

Instantly share code, notes, and snippets.

@maheshwaghmare
Last active February 23, 2018 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maheshwaghmare/f32e9343bccc4fd9c239f448cd057496 to your computer and use it in GitHub Desktop.
Save maheshwaghmare/f32e9343bccc4fd9c239f448cd057496 to your computer and use it in GitHub Desktop.
Get current user roles.
<?php
if( ! function_exists( 'prefix_get_current_user_roles' ) ) :
/**
* Get current user roles
*
* E.g. print_r( prefix_get_current_user_roles() );
*
* Output:
*
* Array
* (
* [0] => administrator
* )
*
* @todo Change `prefix` with your own unique slug.
*
* @since 1.0.0
* @return mixed User roles.
*/
function prefix_get_current_user_roles()
{
// Not logged in? Return false.
if( ! is_user_logged_in() ) {
return false;
}
// Logged in? Return all roles.
return wp_get_current_user()->roles;
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment