bp_get_activity_secondary_avatar( array|string $args = '' )

Return the avatar of the object that action was performed on.

Description

See also

Parameters

$args

(Optional) For a complete description of arguments, see bp_core_fetch_avatar().

  • 'alt'
    (string) Default value varies based on current activity item component.
  • 'type'
    (string) Default: 'full' when viewing a single activity permalink page, otherwise 'thumb'.
  • 'class'
    (string) Default: 'avatar'.
  • 'email'
    (string|bool) Default: email of the activity's user.
  • 'user_id'
    (int|bool) Default: ID of the activity's user.

Default value: ''

Return

(string) The secondary avatar.

Source

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

	function bp_get_activity_secondary_avatar( $args = '' ) {
		global $activities_template;

		$r = wp_parse_args( $args, array(
			'alt'        => '',
			'type'       => 'thumb',
			'width'      => 20,
			'height'     => 20,
			'class'      => 'avatar',
			'link_class' => '',
			'linked'     => true,
			'email'      => false
		) );
		extract( $r, EXTR_SKIP );

		// Set item_id and object (default to user).
		switch ( $activities_template->activity->component ) {
			case 'groups' :
				if ( bp_disable_group_avatar_uploads() ) {
					return false;
				}

				$object  = 'group';
				$item_id = $activities_template->activity->item_id;
				$link    = '';
				$name    = '';

				// Only if groups is active.
				if ( bp_is_active( 'groups' ) ) {
					$group = groups_get_group( $item_id );
					$link  = bp_get_group_permalink( $group );
					$name  = $group->name;
				}

				if ( empty( $alt ) ) {
					$alt = __( 'Group logo', 'buddyboss' );

					if ( ! empty( $name ) ) {
						$alt = sprintf( __( 'Group logo of %s', 'buddyboss' ), $name );
					}
				}

				break;
			case 'blogs' :
				$object  = 'blog';
				$item_id = $activities_template->activity->item_id;
				$link    = home_url();

				if ( empty( $alt ) ) {
					$alt = sprintf( __( 'Profile photo of the author of the site %s', 'buddyboss' ), get_blog_option( $item_id, 'blogname' ) );
				}

				break;
			case 'friends' :
				$object  = 'user';
				$item_id = $activities_template->activity->secondary_item_id;
				$link    = bp_core_get_userlink( $item_id, false, true );

				if ( empty( $alt ) ) {
					$alt = sprintf( __( 'Profile photo of %s', 'buddyboss' ), bp_core_get_user_displayname( $activities_template->activity->secondary_item_id ) );
				}

				break;
			default :
				$object  = 'user';
				$item_id = $activities_template->activity->user_id;
				$email   = $activities_template->activity->user_email;
				$link    = bp_core_get_userlink( $item_id, false, true );

				if ( empty( $alt ) ) {
					$alt = sprintf( __( 'Profile photo of %s', 'buddyboss' ), $activities_template->activity->display_name );
				}

				break;
		}

		/**
		 * Filters the activity secondary avatar object based on current activity item component.
		 *
		 * This is a variable filter dependent on the component used. Possible hooks are
		 * bp_get_activity_secondary_avatar_object_blog, bp_get_activity_secondary_avatar_object_group,
		 * and bp_get_activity_secondary_avatar_object_user.
		 *
		 * @since BuddyPress 1.2.10
		 *
		 * @param string $object Component being displayed.
		 */
		$object  = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object );

		/**
		 * Filters the activity secondary avatar item ID.
		 *
		 * @since BuddyPress 1.2.10
		 *
		 * @param int $item_id ID for the secondary avatar item.
		 */
		$item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );

		// If we have no item_id or object, there is no avatar to display.
		if ( empty( $item_id ) || empty( $object ) ) {
			return false;
		}

		// Get the avatar.
		$avatar = bp_core_fetch_avatar( array(
			'item_id' => $item_id,
			'object'  => $object,
			'type'    => $type,
			'alt'     => $alt,
			'class'   => $class,
			'width'   => $width,
			'height'  => $height,
			'email'   => $email
		) );

		if ( !empty( $linked ) ) {

			/**
			 * Filters the secondary avatar link for current activity.
			 *
			 * @since BuddyPress 1.7.0
			 *
			 * @param string $link      Link to wrap the avatar image in.
			 * @param string $component Activity component being acted on.
			 */
			$link = apply_filters( 'bp_get_activity_secondary_avatar_link', $link, $activities_template->activity->component );

			/**
			 * Filters the determined avatar for the secondary activity item.
			 *
			 * @since BuddyPress 1.2.10
			 *
			 * @param string $avatar Formatted HTML <img> element, or raw avatar URL.
			 */
			$avatar = apply_filters( 'bp_get_activity_secondary_avatar', $avatar );

			return sprintf( '<a href="%s" class="%s">%s</a>',
				$link,
				$link_class,
				$avatar
			);
		}

		/** This filter is documented in bp-activity/bp-activity-template.php */
		return apply_filters( 'bp_get_activity_secondary_avatar', $avatar );
	}

Changelog

Changelog
Version Description
BuddyPress 1.2.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.