Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/29/2020 05:32:05 PM (6 years ago)
Author:
boonebgorges
Message:

Don't delete user data on delete_user hook on Multisite.

The new function bp_remove_user_data_on_delete_user_hook(), which defaults
to false on Multisite and true otherwise, helps BuddyPress to differentiate
between the use of wp_delete_user() to delete a user account from an
installation (typical on non-Multisite) and its use to remove a user from
a site in a Multisite instance.

Props imath.

Fixes #8175.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/notifications/functions.php

    r12158 r12605  
    347347        $this->assertEqualSets( array( $n1, $n2, $n3, $n4, $n5 ), $found1 );
    348348
    349         wp_delete_user( $u );
     349        $this->delete_user( $u );
    350350
    351351        // Check if notifications are deleted.
     
    464464        $this->assertSame( 2, count( $actual['data'] ) );
    465465    }
     466
     467    /**
     468     * @ticket BP8175
     469     */
     470    public function test_notifications_data_should_be_deleted_on_user_delete_non_multisite() {
     471        if ( is_multisite() ) {
     472            $this->markTestSkipped( __METHOD__ . ' requires non-multisite.' );
     473        }
     474
     475        $u = self::factory()->user->create();
     476
     477        $n1 = self::factory()->notification->create( array(
     478            'component_name'    => 'messages',
     479            'component_action'  => 'new_message',
     480            'item_id'           => 99,
     481            'user_id'           => $u,
     482        ) );
     483
     484        $found = bp_notifications_get_notifications_for_user( $u, 'object' );
     485        $this->assertEqualSets( [ $n1 ], wp_list_pluck( $found, 'id' ) );
     486
     487        wp_delete_user( $u );
     488
     489        $found = bp_notifications_get_notifications_for_user( $u, 'object' );
     490        $this->assertEmpty( '', $found );
     491    }
     492
     493    /**
     494     * @ticket BP8175
     495     */
     496    public function test_notifications_data_should_be_deleted_on_user_delete_multisite() {
     497        if ( ! is_multisite() ) {
     498            $this->markTestSkipped( __METHOD__ . ' requires multisite.' );
     499        }
     500
     501        $u = self::factory()->user->create();
     502
     503        $n1 = self::factory()->notification->create( array(
     504            'component_name'    => 'messages',
     505            'component_action'  => 'new_message',
     506            'item_id'           => 99,
     507            'user_id'           => $u,
     508        ) );
     509
     510        $found = bp_notifications_get_notifications_for_user( $u, 'object' );
     511        $this->assertEqualSets( [ $n1 ], wp_list_pluck( $found, 'id' ) );
     512
     513        wpmu_delete_user( $u );
     514
     515        $found = bp_notifications_get_notifications_for_user( $u, 'object' );
     516        $this->assertEmpty( '', $found );
     517    }
     518
     519    /**
     520     * @ticket BP8175
     521     */
     522    public function test_notifications_data_should_not_be_deleted_on_wp_delete_user_multisite() {
     523        if ( ! is_multisite() ) {
     524            $this->markTestSkipped( __METHOD__ . ' requires multisite.' );
     525        }
     526
     527        $u = self::factory()->user->create();
     528
     529        $n1 = self::factory()->notification->create( array(
     530            'component_name'    => 'messages',
     531            'component_action'  => 'new_message',
     532            'item_id'           => 99,
     533            'user_id'           => $u,
     534        ) );
     535
     536        $found = bp_notifications_get_notifications_for_user( $u, 'object' );
     537        $this->assertEqualSets( [ $n1 ], wp_list_pluck( $found, 'id' ) );
     538
     539        wp_delete_user( $u );
     540
     541        $found = bp_notifications_get_notifications_for_user( $u, 'object' );
     542        $this->assertEqualSets( [ $n1 ], wp_list_pluck( $found, 'id' ) );
     543    }
    466544}
Note: See TracChangeset for help on using the changeset viewer.