Last active
February 23, 2018 07:06
-
-
Save maheshwaghmare/f32e9343bccc4fd9c239f448cd057496 to your computer and use it in GitHub Desktop.
Get current user roles.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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