AARONDAS
Member
Posted 1 year ago #
Hello,
On my blog I am creating a directory using "members list", I also have role manager installed, and I have created a author.php page. I would like to display on the profile page:
Your role is: <user_role>
I was wondering if anyone know of a way that I can display the current role, either one of the default roles or 'role manager' roles on the profile page.
Thank you, and I appreciate your help,
Aaron
I use this snippet in my BNS Support plugin to show the current user's role which may accomplish what you are looking for:
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
echo '<strong>Current User Role</strong>: ' . $user_role;
It will only show the first role if the user has more than one assigned to them.
AARONDAS
Member
Posted 1 year ago #
Edward,
This worked great, but I was wondering if you know how I can add this to my members list directory. I can display the wp_user_level in the list, but for some reason I can't display the wp_capabilities.
Do you know how this can be done?
Thanks,
Aaron
ibadullah
Member
Posted 9 months ago #
How to make the first letter capital of user role?
sedemik
Member
Posted 7 months ago #
For example
<?php
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if ($user_role == 'administrator') {
echo 'Administrator';
} elseif ($user_role == 'editor') {
echo 'Editor';
} elseif ($user_role == 'author') {
echo 'Author';
} elseif ($user_role == 'contributor') {
echo 'Contributor';
} elseif ($user_role == 'subscriber') {
echo 'Subscriber';
} else {
echo '<strong>' . $user_role . '</strong>';
}
?>