您现在的位置是:首页 > 教程 > WordPress教程WordPress教程
怎么显示WordPress登录用户的角色
冰彤2023-07-03 22:42:08WordPress教程已有人查阅
导读将下面的代码添加到当前主题functions.php中:在主题模板适当位置添加调用代码:再配合以下的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用户信息调用基本算是全了。应该还差显示用户文章和评论数量,下次再写。
本文标签:
很赞哦! ()
相关文章
随机图文
-
wordpress主题安装方法
WordPress的强大,很大程度是因为它良好的扩展和众多的主题、插件支持。访问后台 – 外观 -主题 – 安装主题,输入主题关键字,搜索 -
WordPress临时关闭网站进行维护的方法
有时可能会因为各种原因导致我们的网站出现访问错误,此时我们就需要临时关闭站点进行维护,那么我们该如何临时关闭站点进行维护呢 -
drupal与wordpress的优势,哪个更容易上手
WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。 -
wordpress文章发布不了的解决方法
最近有一个WordPress主机客户反馈说,他WordPress网站,在升级到WordPress 5.2版本以后,无法发布文章了。
留言与评论 (共有 条评论) |