Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/11/2021 01:40:24 PM (3 years ago)
Author:
imath
Message:

Make sure the new_avatar activity can use the avatar crop results

Since [13175] the BP_Attachment_Avatar::crop() method include the timestamp the avatar was generated on into its returned array. This array is now transported into the action the function creating a new_avatar activity hooks to. This function (bp_members_new_avatar_activity()) now accepts 3 more parameters included the transported crop results. This makes it possible to use the timestamp when the avatar was generated on as the new_avatar activity recorded time. Doing so, we don't need to add an extra activity meta to store the name of the avatar file to be sure to display the avatar the user had at the time the activity was created.

Props vapvarun, oztaser

See #8581

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-activity.php

    r13155 r13177  
    167167 *
    168168 * @since 8.0.0
    169  *
    170  * @param int $user_id The user id the avatar was set for.
    171  */
    172 function bp_members_new_avatar_activity( $user_id = 0 ) {
     169 * @since 10.0.0 Adds the `$type`, `$crop_data` and `$cropped_avatar` parameters.
     170 *
     171 * @param int    $user_id        The user id the avatar was set for.
     172 * @param string $type           The way the avatar was set ('camera' or `crop`).
     173 * @param array  $crop_data      Array of parameters passed to the crop handler.
     174 * @param array  $cropped_avatar Array containing the full, thumb avatar and the timestamp.
     175 */
     176function bp_members_new_avatar_activity( $user_id = 0, $type = '', $crop_data = array(), $cropped_avatar = array() ) {
    173177
    174178    // Bail if activity component is not active.
     
    231235    }
    232236
     237    $recorded_time = '';
     238    if ( isset( $cropped_avatar['timestamp'] ) && $cropped_avatar['timestamp'] ) {
     239        $recorded_time = date( 'Y-m-d H:i:s', $cropped_avatar['timestamp'] );
     240    }
     241
    233242    // Add the activity.
    234     bp_activity_add(
     243    $activity_id = bp_activity_add(
    235244        array(
    236             'user_id'   => $user_id,
    237             'component' => $bp->members->id,
    238             'type'      => 'new_avatar',
     245            'user_id'       => $user_id,
     246            'component'     => $bp->members->id,
     247            'type'          => 'new_avatar',
     248            'recorded_time' => $recorded_time,
    239249        )
    240250    );
    241251}
    242 add_action( 'bp_members_avatar_uploaded', 'bp_members_new_avatar_activity' );
     252add_action( 'bp_members_avatar_uploaded', 'bp_members_new_avatar_activity', 10, 4 );
Note: See TracChangeset for help on using the changeset viewer.