Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to add extra class to Avatars


  • noobiestrikesagain
    Participant

    @noobiestrikesagain

    Hey,

    I want to add an extra class to the avatars based on user-id.

    Basically, I’m trying to differentiate admins from members..

    Here’s a sample of what I’m trying (Trying to explain the logic. I know filters won’t work like this):

    function avatar_extra_class($user_id) {
    if (user_can( $user_id, 'manage_options' ) ) {
    addClass "admin-account";
    }
    elseif (user_can( $user_id, 'edit_published_posts' ) ) {
    addClass "Author-account";
    } else {
    addClass "General-account";
    }
    }
    add_filter( 'bp_get_avatar', 'avatar_extra_class');

    I shall be very grateful for any suggestions/recommendation on the same! 🙂

    Thank you in Advance!

Viewing 2 replies - 1 through 2 (of 2 total)

  • Renato Alves
    Moderator

    @espellcaste

    You can try something like this:

    function yousite_filter_class( $class, $item_id, $object, $params ) {
    	if ( current_user_can( 'manage_options' ) ) {
    		$class = 'admin-account';
    	} elseif ( current_user_can( 'edit_published_posts' ) ) {
    		$class = 'Author-account';
    	} else {
    		$class = 'General-account';
    	}
    
    	return $class;
    }
    add_filter( 'bp_core_avatar_class', 'yousite_filter_class', 10, 4 );

    noobiestrikesagain
    Participant

    @noobiestrikesagain

    Hey,

    Thanks that worked perfectly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar