Ticket #8388: 8388.03.diff
File 8388.03.diff, 2.5 KB (added by , 4 years ago) |
---|
-
src/bp-xprofile/bp-xprofile-functions.php
842 842 * @since 1.0.0 843 843 * 844 844 * @param int $user_id The ID of the deleted user. 845 * @return int Number of fields deleted. 845 846 */ 846 847 function xprofile_remove_data( $user_id ) { 847 BP_XProfile_ProfileData::delete_data_for_user( $user_id ); 848 global $wpdb; 849 $bp = buddypress(); 850 851 $field_ids = $wpdb->get_col( $wpdb->prepare( "SELECT field_id FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) ); 852 853 foreach ( $field_ids as $field_id ) { 854 xprofile_delete_field_data( $field_id, $user_id ); 855 } 856 857 return count( $field_ids ); 848 858 } 849 859 add_action( 'wpmu_delete_user', 'xprofile_remove_data' ); 850 860 add_action( 'bp_make_spam_user', 'xprofile_remove_data' ); -
src/bp-xprofile/classes/class-bp-xprofile-profiledata.php
674 674 * @since 1.0.0 675 675 * 676 676 * @param int $user_id User ID to remove data for. 677 * @return false|int677 * @return int 678 678 */ 679 679 public static function delete_data_for_user( $user_id ) { 680 global $wpdb; 681 682 $bp = buddypress(); 683 684 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) ); 680 return xprofile_remove_data( $user_id ); 685 681 } 686 682 687 683 /** -
tests/phpunit/testcases/xprofile/class-bp-xprofile-profiledata.php
419 419 $this->assertEquals( $expected, BP_XProfile_ProfileData::get_all_for_user( $u ) ); 420 420 } 421 421 422 /** 423 * @ticket BP8388 424 * @group xprofile_remove_data 425 */ 426 public function test_cache_invalidated_when_xprofile_remove_data_called() { 427 $u = self::factory()->user->create(); 428 $g = self::factory()->xprofile_group->create(); 429 $f = self::factory()->xprofile_field->create( array( 430 'field_group_id' => $g, 431 ) ); 432 433 xprofile_set_field_data( $f, $u, 'Foo' ); 434 // Prime the cache. 435 xprofile_get_field_data( $f, $u ); 436 xprofile_remove_data( $u ); 437 438 $d = new BP_XProfile_ProfileData( $f, $u ); 439 $this->assertFalse( $d->exists() ); 440 } 441 422 442 public function filter_time() { 423 443 return $this->last_updated; 424 444 }