Home > CMS Tutorial > WordPress > body text

How to display WordPress login user roles

藏色散人
Release: 2019-11-23 11:13:13
forward
2776 people have browsed it

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;
}
Copy after login

Add the calling code at the appropriate location in the theme template:

<?php echo get_user_role(); ?>
Copy after login

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";
?>
Copy after login

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!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!