bp_activity_comments_user_avatars( array $args = array() )

Echo a list of linked avatars of users who have commented on the current activity item.


Description Description

Use this function to easily output activity comment authors’ avatars.

Avatars are wrapped in

  • elements, but you’ve got to provide your own


  • Top ↑

    Parameters Parameters

    $args

    (Optional) See bp_core_fetch_avatar().

    Default value: array()


    Top ↑

    Source Source

    File: bp-activity/bp-activity-template.php

    function bp_activity_comments_user_avatars( $args = array() ) {
    
    	$r = bp_parse_args( $args, array(
    		'height' => false,
    		'html'   => true,
    		'type'   => 'thumb',
    		'width'  => false,
    	) );
    
    	// Get the user IDs of everyone who has left a comment to the current activity item.
    	$user_ids = bp_activity_get_comments_user_ids();
    	$output   = array();
    	$retval   = '';
    
    	if ( ! empty( $user_ids ) ) {
    		foreach ( (array) $user_ids as $user_id ) {
    
    			// Skip an empty user ID.
    			if ( empty( $user_id ) ) {
    				continue;
    			}
    
    			// Get profile link for this user.
    			$profile_link = bp_core_get_user_domain( $user_id );
    
    			// Get avatar for this user.
    			$image_html   = bp_core_fetch_avatar( array(
    				'item_id' => $user_id,
    				'height'  => $r['height'],
    				'html'    => $r['html'],
    				'type'    => $r['type'],
    				'width'   => $r['width']
    			) );
    
    			// If user has link & avatar, add them to the output array.
    			if ( ! empty( $profile_link ) && ! empty( $image_html ) ) {
    				$output[] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $profile_link ), $image_html );
    			}
    		}
    
    		// If output array is not empty, wrap everything in some list items.
    		if ( ! empty( $output ) ) {
    			$retval = '<li>' . implode( '</li><li>', $output ) . '</li>';
    		}
    	}
    
    	/**
    	 * Filters the list of linked avatars for users who have commented on the current activity item.
    	 *
    	 * @since 1.7.0
    	 *
    	 * @param string $retval HTML markup for the list of avatars.
    	 * @param array  $r      Array of arguments used for each avatar.
    	 * @param array  $output Array of each avatar found, before imploded into single string.
    	 */
    	echo apply_filters( 'bp_activity_comments_user_avatars', $retval, $r, $output );
    }
    

    Top ↑

    Changelog Changelog

    Changelog
    Version Description
    1.7.0 Introduced.

    Top ↑

    User Contributed Notes User Contributed Notes

    You must log in before being able to contribute a note or feedback.