Skip to:
Content

BuddyPress.org

Ticket #6780: 6780.01.patch

File 6780.01.patch, 2.4 KB (added by r-a-y, 10 years ago)
  • src/bp-friends/bp-friends-activity.php

     
    384384        ) );
    385385}
    386386add_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4 );
     387
     388/**
     389 * Deletes friendship activity items when a user is deleted.
     390 *
     391 * @since 2.5.0
     392 *
     393 * @param int $user_id The ID of the user being deleted.
     394 */
     395function bp_friends_delete_activity_on_user_delete( $user_id = 0 ) {
     396        if ( ! bp_is_active( 'activity' ) ) {
     397                return;
     398        }
     399
     400        bp_activity_delete( array(
     401                'component'         => buddypress()->friends->id,
     402                'type'              => 'friendship_created',
     403                'secondary_item_id' => $user_id
     404        ) );
     405}
     406add_action( 'friends_remove_data', 'bp_friends_delete_activity_on_user_delete' );
     407 No newline at end of file
  • tests/phpunit/testcases/friends/activity.php

     
    108108                friends_add_friend( $u2, $u1 );
    109109                $friendship_id = friends_get_friendship_id( $u2, $u1 );
    110110
    111                 // Set current user to u1 to accepte the friendship
     111                // Set current user to u1 to accept the friendship
    112112                $this->set_current_user( $u1 );
    113113                friends_accept_friendship( $friendship_id );
    114114
     
    184184
    185185                $this->assertTrue( count( $check['activities'] ) == 1 );
    186186        }
     187
     188        /**
     189         * @group friends_delete_activity
     190         */
     191        public function test_delete_friendship_activity_on_user_delete() {
     192                $old_user = get_current_user_id();
     193
     194                $u1 = $this->factory->user->create();
     195                $u2 = $this->factory->user->create();
     196
     197                friends_add_friend( $u2, $u1 );
     198                $friendship_id = friends_get_friendship_id( $u2, $u1 );
     199
     200                // Set current user to u1 to accept the friendship
     201                $this->set_current_user( $u1 );
     202                friends_accept_friendship( $friendship_id );
     203
     204                // Reset the current user
     205                $this->set_current_user( $old_user );
     206
     207                // Delete $u1.
     208                wp_delete_user( $u1 );
     209
     210                // 'friendship_created' activity item should not exist.
     211                $friendship_activity = bp_activity_get( array(
     212                        'component'   => buddypress()->friends->id,
     213                        'filter'      => array(
     214                                'action' => array( 'friendship_created' ),
     215                                'primary_id' => $friendship_id,
     216                        )
     217                ) );
     218
     219                $this->assertEmpty( $friendship_activity['activities'] );
     220        }
    187221}
    188222