if ( current_user_can( 'manage_options' ) ) {
echo 'Admin';
} else if ( current_user_can( 'edit_pages' ) ) {
echo 'Editor';
} else if ( current_user_can( 'publish_posts' ) ) {
echo 'Author';
} else if ( current_user_can( 'read' ) ) {
echo 'Subscriber';
}
//// or Not tested
foreach ( $comment_users as $user_id ) {
wp23234_show_user_role( $user_id );
}
function wp23234_show_user_role( $user_id ) {
$data = get_userdata( $user_id );
$roles = $data->roles;
if ( in_array( $roles, 'administrator' ) ) {
echo 'Administrator';
} else if ( in_array( $roles, 'editor' ) ) {
echo 'Editor';
} else if ( in_array( $roles, 'author' ) ) {
echo 'Author';
} else if ( in_array ( $roles, 'subscriber' ) ) {
echo 'Subscriber';
}
}
/// Or Switch
<?php
global $current_user;
get_currentuserinfo();
switch (true) {
case ( user_can( $current_user, "subscriber") ):
break;
case ( user_can( $current_user, "contributor") ):
break;
case ( user_can( $current_user, "administrator") ):
break;
}
?>
///
<?php
global $current_user;
get_currentuserinfo();
switch (true) {
case ( user_can( $current_user, "subscriber") ):
echo '<img src="http:www.impho.com/images/001.jpg">';
break;
case ( user_can( $current_user, "contributor") ):
echo '<img src="http:www.impho.com/images/002.jpg">';
break;
case ( user_can( $current_user, "administrator") ):
echo '<img src="http:www.impho.com/images/003.jpg">';
break;
}
?>