且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 wordpress 用户组中使用 php

更新时间:2023-12-01 22:37:16

试试这个,其中 $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);
}