Role label like on here

6.41K viewsGeneral
0

Hi,

I searched, but could not find anything on how to have role labels like Staff do on here.

How is this possible?

Thanks!

Link is missing

Which link to you mean? I guess he`s referring to this: http://fs5.directupload.net/images/160609/mig2tv8e.png

i think that might work with user roles

@Zoker yes that’s what I mean 🙂 Any idea how to add? Thanks

I guess @rahularyan has to answer that, I don’t have any idea

1

I was able to achieve this by modifying a bit the code from this question: https://anspress.io/questions/question/displaying-pmp-membership-type-under-name/

 

You just need to remove the part that checks PMPro user level. Here is the code I used:

/**
 * Append user level information
 *@param  string $name User name.
 *@param  array  $args Name arguments.
 **/
function io_ap_user_display_name( $name, $args ) {
	if ( user_can( $args['user_id'], 'ap_moderator' ) || is_super_admin( $args['user_id'] ) ) {
		$level_name = 'Staff';
	}
	if ( empty( $level_name ) ) {
		return $name;
	}
	if ( $args['html'] ) {
		return $name . '<span class="role-label level-'.strtolower($level_name ).'">'. $level_name.'</span>';
	}
	return $name . ' ('. $level_name.')';
}
add_filter('ap_user_display_name', 'io_ap_user_display_name', 10, 2 );
commented on answer

Thank you for this code ! I’d like to change the color of the text but I don’t how to do it …

Can you help me please ? 🙂

You are viewing 1 out of 2 answers, click here to view all answers.