WP_User > which role has the logged in user
-
After seeing, that a lot of people would need it and not finding any documentation or any code that works, here goes my sollution:
$cur_user_roles = $current_user->roles; foreach($cur_user_roles as $cur_user_roles_value) { $role_to_compare = $cur_user_roles_value; } if($role_to_compare == 'administrator') { echo "Administrator "; } elseif($role_to_compare == 'editor') { echo "Editor "; } elseif($role_to_compare == 'author') { echo "Author "; } elseif($role_to_compare == 'contributor') { echo "Contributer "; } elseif($role_to_compare == 'subscriber') { echo "Subscriber "; } else { echo "<i>Att.: user got no actual role in the system</i> "; }
It would even work, when a user would have got multiple roles (downgrading – highest is a match).
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘WP_User > which role has the logged in user’ is closed to new replies.