WordPress 网站显示登录用户角色的方法

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

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

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

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

<?php echo get_user_role(); ?>

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

//write by https://2bcd.com
<?phpglobal $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";?>

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秃头程序员宝贝

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值