[WordPress教程] 显示WordPress登录用户角色 -静鱼客栈

2021-10-09 0 808

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

 

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

静鱼客栈 学习中心 [WordPress教程] 显示WordPress登录用户角色 -静鱼客栈 https://wp.muooy.cn/10622.html

静鱼客栈的帅逼站长~

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务