Home >CMS Tutorial >WordPress >How to display WordPress login user roles

How to display WordPress login user roles

藏色散人
藏色散人forward
2019-11-23 11:13:132842browse

The WordPress Getting Started Tutorial column below will share with you a piece of code for WordPress to display the logged-in user role.

How to display WordPress login user roles

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 &#39;用户名: &#39; . $current_user->user_login . "\n";
echo &#39;用户邮箱: &#39; . $current_user->user_email . "\n";
echo &#39;名字: &#39; . $current_user->user_firstname . "\n";
echo &#39;姓氏: &#39; . $current_user->user_lastname . "\n";
echo &#39;公开显示名: &#39; . $current_user->display_name . "\n";
echo &#39;用户 ID:&#39; . $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!

Statement:
This article is reproduced at:zmingcx.com. If there is any infringement, please contact admin@php.cn delete