bp_get_activity_avatar( array|string $args = '' )
Return the avatar of the user that performed the action.
Description
See also
- bp_core_fetch_avatar(): For a description of the arguments.
Parameters
- $args
-
(Optional) Arguments are listed here with an explanation of their defaults. For more information about the arguments, see bp_core_fetch_avatar().
- 'alt'
(string) Default: 'Profile picture of [user name]' if activity user name is available, otherwise 'Profile picture'. - 'class'
(string) Default: 'avatar'. - 'email'
(string|bool) Default: Email of the activity's associated user, if available. Otherwise false. - 'type'
(string) Default: 'full' when viewing a single activity permalink page, otherwise 'thumb'. - 'user_id'
(int|bool) Default: ID of the activity's user.
Default value: ''
- 'alt'
Return
(string) User avatar string.
Source
File: bp-activity/bp-activity-template.php
function bp_get_activity_avatar( $args = '' ) {
global $activities_template;
$bp = buddypress();
// On activity permalink pages, default to the full-size avatar.
$type_default = bp_is_single_activity() ? 'full' : 'thumb';
// Within the activity comment loop, the current activity should be set
// to current_comment. Otherwise, just use activity.
$current_activity_item = isset( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : $activities_template->activity;
// Activity user display name.
$dn_default = isset( $current_activity_item->display_name ) ? $current_activity_item->display_name : '';
// Prepend some descriptive text to alt.
$alt_default = !empty( $dn_default ) ? sprintf( __( 'Profile photo of %s', 'buddyboss' ), $dn_default ) : __( 'Profile photo', 'buddyboss' );
$defaults = array(
'alt' => $alt_default,
'class' => 'avatar',
'email' => false,
'type' => $type_default,
'user_id' => false
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
if ( !isset( $height ) && !isset( $width ) ) {
// Backpat.
if ( isset( $bp->avatar->full->height ) || isset( $bp->avatar->thumb->height ) ) {
$height = ( 'full' == $type ) ? $bp->avatar->full->height : $bp->avatar->thumb->height;
} else {
$height = 20;
}
// Backpat.
if ( isset( $bp->avatar->full->width ) || isset( $bp->avatar->thumb->width ) ) {
$width = ( 'full' == $type ) ? $bp->avatar->full->width : $bp->avatar->thumb->width;
} else {
$width = 20;
}
}
/**
* Filters the activity avatar object based on current activity item component.
*
* This is a variable filter dependent on the component used.
* Possible hooks are bp_get_activity_avatar_object_blog,
* bp_get_activity_avatar_object_group, and bp_get_activity_avatar_object_user.
*
* @since BuddyPress 1.1.0
*
* @param string $component Component being displayed.
*/
$object = apply_filters( 'bp_get_activity_avatar_object_' . $current_activity_item->component, 'user' );
$item_id = !empty( $user_id ) ? $user_id : $current_activity_item->user_id;
/**
* Filters the activity avatar item ID.
*
* @since BuddyPress 1.2.10
*
* @param int $item_id Item ID for the activity avatar.
*/
$item_id = apply_filters( 'bp_get_activity_avatar_item_id', $item_id );
// If this is a user object pass the users' email address for Gravatar so we don't have to prefetch it.
if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $current_activity_item->user_email ) ) {
$email = $current_activity_item->user_email;
}
/**
* Filters the value returned by bp_core_fetch_avatar.
*
* @since BuddyPress 1.1.3
*
* @param array $value HTML image element containing the activity avatar.
*/
return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array(
'item_id' => $item_id,
'object' => $object,
'type' => $type,
'alt' => $alt,
'class' => $class,
'width' => $width,
'height' => $height,
'email' => $email
) ) );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.1.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.