在 wordpress 用户组中使用 php [英] In wordpress User group using php
本文介绍了在 wordpress 用户组中使用 php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用php显示(回显)用户组
How to display (echo) the user group using php.
我已显示用户名、用户电子邮件和用户 ID.
I have displayed user name, and user email and user ID.
但我也想添加用户组.
怎么做?
现在我已经创建了一个 php 代码来列出姓名、ID 和电子邮件地址.
Now I have created a php code to list name, id and email address.
<?php
$order = 'user_nicename';
$users = get_users( 'search=*' );
foreach($users as $user) :
echo $user->user_nicename ; ?>
echo $user->user_firstname; ?>
echo $user->user_lastname; ?>
echo $user->user_email; ?>
endforeach;
?>
推荐答案
试试这个,其中 $user_id
是你想要显示角色的用户的 id(group)
Try this, where $user_id
is the id of the user you want to display the role(group)
$user = new WP_User( $user_id );
$user_roles = $user->roles;
foreach($user_roles as $role) {
echo $role;
}
更新为适用于 UAM WordPress 插件:
试试这个
global $userAccessManager;
if (isset($userAccessManager)) {
$userId = <insert-user-id-here>;
$uamAccessHandler = $userAccessManager->getAccessHandler();
$userGroupsForUser = $uamAccessHandler->getUserGroupsForObject('user', $userId);
print_r($userGroupsForUser);
}
这篇关于在 wordpress 用户组中使用 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文