HI,欢迎来到我爱模板网!

显示WordPress登录用户角色

WordPress 进一步完善前台登录用户信息,本文再分享一段WordPress显示登录用户角色的代码。 将下面的代码添加到当前主题functions.php中: function get_user_role() { global $current_user; $user_roles = $current_user-&...
显示WordPress登录用户角色
WordPress

进一步完善前台登录用户信息,本文再分享一段WordPress显示登录用户角色的代码。

将下面的代码添加到当前主题functions.php中:

function get_user_role() {
    global $current_user;
    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);
    return $user_role;
}

在主题模板适当位置添加调用代码:

<?php echo get_user_role(); ?>

再配合以下的WordPress用户信息函数:

<?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";
?>

WordPress用户信息调用基本算是全了。应该还差显示用户文章和评论数量,下次再写。

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

WordPress文章中插入图片同样的主题代码不一样的原因

2023-2-16 23:47:07

wordpress教程

wordpress教程之 WordPress 固定链接设置

2023-2-16 23:47:10

【腾讯云】11.11云上盛惠!云服务器首年1.8折起,买1年送3个月!
11.11云上盛惠!海量产品·轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。
查看更多相关信息>>
站长

(工作日 10:00 - 22:30 为您服务)

2026-01-30 11:09:54

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

猜你想问:

  • 购买的模板免费包安装吗?

  • 这个演示地址有吗?

  • 购买vip会员可以下载哪些模板?

您的留言我们已经收到,我们将会尽快跟您联系!
取消
立即选择任一渠道联系我们