The WordPress Getting Started Tutorial column below will share with you a piece of code for WordPress to display the logged-in user role.
Add the following code to the current theme functions.php:
function get_user_role() { global $current_user; $user_roles = $current_user->roles; $user_role = array_shift($user_roles); return $user_role; }
Add the calling code at the appropriate location in the theme template:
<?php echo get_user_role(); ?>
Couple it with the following WordPress user information function:
<?php global $current_user; get_currentuserinfo(); echo '用户名: ' . $current_user->user_login . "\n"; echo '用户邮箱: ' . $current_user->user_email . "\n"; echo '名字: ' . $current_user->user_firstname . "\n"; echo '姓氏: ' . $current_user->user_lastname . "\n"; echo '公开显示名: ' . $current_user->display_name . "\n"; echo '用户 ID:' . $current_user->ID . "\n"; ?>
The WordPress user information call is basically complete. There should be more time to display the number of user articles and comments, so I’ll write that next time.
The above is the detailed content of How to display WordPress login user roles. For more information, please follow other related articles on the PHP Chinese website!