Ticket #5857: 5857.04.patch
File 5857.04.patch, 2.8 KB (added by , 9 years ago) |
---|
-
src/bp-blogs/bp-blogs-functions.php
diff --git src/bp-blogs/bp-blogs-functions.php src/bp-blogs/bp-blogs-functions.php index c10af26..35e4f4d 100644
function bp_blogs_remove_data( $user_id ) { 1422 1422 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' ); 1423 1423 add_action( 'delete_user', 'bp_blogs_remove_data' ); 1424 1424 add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' ); 1425 1426 /** 1427 * Restore all blog associations for a given user 1428 * 1429 * @since BuddyPress (2.2.0) 1430 * 1431 * @param int $user_id ID whose blog data should be restored. 1432 * @uses get_blogs_of_user() Get the blogs a user belongs to. 1433 * @uses bp_blogs_add_user_to_blog() Record a user's association with a blog. 1434 * @return bool|null Returns false on failure. 1435 */ 1436 function bp_blogs_restore_data( $user_id = 0 ) { 1437 if ( ! is_multisite() ) { 1438 return false; 1439 } 1440 1441 // Get the user's blogs 1442 $user_blogs = get_blogs_of_user( $user_id ); 1443 1444 if ( empty( $user_blogs ) ) { 1445 return false; 1446 } 1447 1448 $blogs = array_keys( $user_blogs ); 1449 1450 foreach ( $blogs as $blog_id ) { 1451 bp_blogs_add_user_to_blog( $user_id, false, $blog_id ); 1452 } 1453 } 1454 add_action( 'bp_make_ham_user', 'bp_blogs_restore_data', 10, 1 ); -
tests/phpunit/testcases/blogs/functions.php
diff --git tests/phpunit/testcases/blogs/functions.php tests/phpunit/testcases/blogs/functions.php index b2ee4eb..82b34c6 100644
class BP_Tests_Blogs_Functions extends BP_UnitTestCase { 280 280 } 281 281 282 282 /** 283 * @group bp_blogs_restore_data 284 */ 285 public function test_bp_blogs_restore_data() { 286 if ( ! is_multisite() ) { 287 return; 288 } 289 290 // Create a regular member 291 $u = $this->factory->user->create(); 292 293 // Create blogs 294 $b1 = $this->factory->blog->create( array( 'user_id' => $u, 'path' => '/b1_blogs_restore' ) ); 295 $b2 = $this->factory->blog->create( array( 'user_id' => $u, 'path' => '/b2_blogs_restore' ) ); 296 297 $expected = array( 298 $b1 => $b1, 299 $b2 => $b2 300 ); 301 302 // Mark the user as spam 303 bp_core_process_spammer_status( $u, 'spam' ); 304 305 // get all blogs for user 306 $blogs = bp_blogs_get_blogs_for_user( $u, true ); 307 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 308 309 $this->assertNotEquals( $expected, array_map( 'intval', $blog_ids ), 'User marked as spam should not have any blog registered' ); 310 311 // Ham the user 312 bp_core_process_spammer_status( $u, 'ham' ); 313 314 // get all blogs for user 315 $blogs = bp_blogs_get_blogs_for_user( $u, true ); 316 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 317 318 $this->assertEquals( $expected, array_map( 'intval', $blog_ids ) ); 319 } 320 321 /** 283 322 * @group bp_blogs_catch_transition_post_status 284 323 */ 285 324 public function test_transition_post_status_publish_to_publish() {