Created
November 26, 2012 07:01
-
-
Save tobedoit/4146948 to your computer and use it in GitHub Desktop.
Wordpress: display current user role
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
/* Display Current User Role *************************************************************************** */ | |
/* http://wordpress.org/support/topic/how-to-get-the-current-logged-in-users-role ********************** */ | |
/* !로그인 회원역할 표시 *********************************************************************************** */ | |
/* <?php echo get_current_user_role(); ?> in your template ******************************************** */ | |
function get_current_user_role() { | |
global $wp_roles; | |
$current_user = wp_get_current_user(); | |
$roles = $current_user->roles; | |
$role = array_shift($roles); | |
return isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function get_all_current_user_rolles() {
global $wp_roles;
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
echo '<ul>';
foreach( $roles as $role ){
echo '<li>' . $wp_roles->roles[ $role ]['name'] . '</li';
}
echo '</ul';
}
}
add_shortcode( 'get_all_currentuserrole_shortcode', 'get_all_current_user_rolles');`
@dJunkyKode Almost five years later but it works for me.
thanks you @tobedoit