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

1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
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.