User roles not displaying

Can anyone explain why I cannot see the role from the code below:$userID = get_current_user_id();$user = get_userdata(u

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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745432979a4627477.html

相关推荐

  • User roles not displaying

    Can anyone explain why I cannot see the role from the code below:$userID = get_current_user_id();$user = get_userdata(u

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信