Do you wish to show role name of current user?
Yes i have change the name of roles whith this plugin and now i want add the rolename to the comments! In addition to the name
global $current_user, $wp_roles;
echo 'Current user role name: '. $wp_roles->role_names[$current_user->roles[0]];
Nice but show all user as Administartor?
Replace $current_user to the comment’s author user object, which you may get by his user_id:
$user = get_user_by('id', $user_id);
So?
<?php global $user = get_user_by('id', $user_id);
echo 'Current user role name: '. $wp_roles->role_names[$current_user->roles[0]]; ?>
this not work!
This will not work as it does not have sense.
You should get comment author value somewhere, possibly from the comment record. I suppose that you put into the $user_id variable.
Then code will be looked like:
global $wp_roles;
// take comment author user ID somewhere. I suppose that you have comment record:
$user = get_user_by('id', $comment->user_id);
echo 'Current user role name: '. $wp_roles->role_names[$user->roles[0]]; ?>
Thats work perfectly thank you!!!!!!!!!!!!!!!!!!!!
is it possible add “Guest” to guest comments?
Add conditional output:
global $wp_roles;
if (!empty($comment->user_id)) {
$user = get_user_by('id', $comment->user_id);
echo 'Current user role name: '. $wp_roles->role_names[$user->roles[0]];
} else {
echo 'Guest';
}
Please Help, Tell me how to show in my account page all roles assigned to user, and how to exclude from whith list some roles?
Thank you