Skip to:
Content

BuddyPress.org


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

Remove a new_avatar activity when an avatar was deleted from history

Once the user removed an item from their avatars story, the corresponding new_avatar also needs to be deleted.

Props vapvarun, oztaser

See #8581

File:
1 edited

Legend:

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

    r13177 r13180  
    251251}
    252252add_action( 'bp_members_avatar_uploaded', 'bp_members_new_avatar_activity', 10, 4 );
     253
     254/**
     255 * Remove the `new_avatar` activity corresponding to the deleted previous avatar.
     256 *
     257 * @since 10.0.0
     258 *
     259 * @param int $user_id   The user ID.
     260 * @param int $timestamp The timestamp when the activity was created.
     261 * @return bool True on success. False otherwise.
     262 */
     263function bp_members_remove_previous_avatar_activity( $user_id = 0, $timestamp = 0 ) {
     264    if ( ! $user_id || ! $timestamp || ! bp_is_active( 'activity' ) ) {
     265        return false;
     266    }
     267
     268    // Look for a `new_avatar` activity corresponding to the date and user.
     269    $activity_id = BP_Activity_Activity::get_id(
     270        array(
     271            'user_id'       => $user_id,
     272            'component'     => buddypress()->members->id,
     273            'type'          => 'new_avatar',
     274            'date_recorded' => date( 'Y-m-d H:i:s', $timestamp ),
     275        )
     276    );
     277
     278    if ( $activity_id ) {
     279        return bp_activity_delete(
     280            array(
     281                'id' => $activity_id,
     282            )
     283        );
     284    }
     285
     286    return false;
     287}
     288add_action( 'bp_previous_user_avatar_deleted', 'bp_members_remove_previous_avatar_activity', 10, 2 );
Note: See TracChangeset for help on using the changeset viewer.