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 12 Answers
Reset to default 1You 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);