最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

User roles not displaying

programmeradmin2浏览0评论

Can anyone explain why I cannot see the role from the code below:

$userID = get_current_user_id();
$user = get_userdata(userID);
<?php echo $user->roles; ?>

but I can see all the other user data such as

<?php echo $user->ID; ?>
<?php echo $user->user_login; ?>

I'm following this documentation.

Can anyone explain why I cannot see the role from the code below:

$userID = get_current_user_id();
$user = get_userdata(userID);
<?php echo $user->roles; ?>

but I can see all the other user data such as

<?php echo $user->ID; ?>
<?php echo $user->user_login; ?>

I'm following this documentation.

Share Improve this question edited Jun 6, 2019 at 6:41 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Jun 6, 2019 at 6:27 rosszrossz 1
Add a comment  | 

2 Answers 2

Reset to default 1

You can't see any roles printed, because the ->roles field is an Array, so you can't print it using echo. User print_r instead.

You also have an error in this line:

$user = get_userdata(userID);

There is no such thing like userID - it should be $userID.

Please change

$user = get_userdata(userID);

To

$user = get_userdata(YOUR_USER_ID_VARIABLE);

And check using print_r($user->roles);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论