Ticket #5857: 5857.02.patch
| File 5857.02.patch, 2.8 KB (added by , 11 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 caffa1e..8846a97 100644
function bp_blogs_remove_data( $user_id ) { 1312 1312 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' ); 1313 1313 add_action( 'delete_user', 'bp_blogs_remove_data' ); 1314 1314 add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' ); 1315 1316 /** 1317 * Restore all blog associations for a given user 1318 * 1319 * @since BuddyPress (2.2.0) 1320 * 1321 * @param int $user_id ID whose blog data should be restored. 1322 * @uses get_blogs_of_user() Get the blogs a user belongs to. 1323 * @uses bp_blogs_add_user_to_blog() Record a user's association with a blog. 1324 * @return bool|null Returns false on failure. 1325 */ 1326 function bp_blogs_restore_data( $user_id = 0 ) { 1327 if ( ! is_multisite() ) { 1328 return false; 1329 } 1330 1331 // Get the user's blogs 1332 $user_blogs = get_blogs_of_user( $user_id ); 1333 1334 if ( empty( $user_blogs ) ) { 1335 return false; 1336 } 1337 1338 $blogs = array_keys( $user_blogs ); 1339 1340 foreach ( $blogs as $blog_id ) { 1341 bp_blogs_add_user_to_blog( $user_id, false, $blog_id ); 1342 } 1343 } 1344 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..e235fb1 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 $old_user = get_current_user_id(); 291 292 // Create a regular member 293 $u = $this->factory->user->create(); 294 295 // Create blogs 296 $b1 = $this->factory->blog->create( array( 'user_id' => $u ) ); 297 $b2 = $this->factory->blog->create(); 298 299 add_user_to_blog( $b2, $u, 'contributor' ); 300 301 $expected = array( 302 $b1 => $b1, 303 $b2 => $b2 304 ); 305 306 bp_blogs_record_existing_blogs(); 307 308 // Mark the user as spam 309 bp_core_process_spammer_status( $u, 'spam' ); 310 311 // get all blogs for user 312 $blogs = bp_blogs_get_blogs_for_user( $u, true ); 313 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 314 315 $this->assertFalse( $expected == array_map( 'intval', $blog_ids ), 'User marked as spam should not have any blog registered' ); 316 317 // Ham the user 318 bp_core_process_spammer_status( $u, 'ham' ); 319 320 // get all blogs for user 321 $blogs = bp_blogs_get_blogs_for_user( $u, true ); 322 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 323 324 $this->assertEquals( $expected, array_map( 'intval', $blog_ids ) ); 325 } 326 327 /** 283 328 * @group bp_blogs_catch_transition_post_status 284 329 */ 285 330 public function test_transition_post_status_publish_to_publish() {