Changeset 9280
- Timestamp:
- 12/24/2014 09:26:41 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-blogs/bp-blogs-functions.php
r9231 r9280 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 */ 1433 function bp_blogs_restore_data( $user_id = 0 ) { 1434 if ( ! is_multisite() ) { 1435 return; 1436 } 1437 1438 // Get the user's blogs 1439 $user_blogs = get_blogs_of_user( $user_id ); 1440 if ( empty( $user_blogs ) ) { 1441 return; 1442 } 1443 1444 $blogs = array_keys( $user_blogs ); 1445 1446 foreach ( $blogs as $blog_id ) { 1447 bp_blogs_add_user_to_blog( $user_id, false, $blog_id ); 1448 } 1449 } 1450 add_action( 'bp_make_ham_user', 'bp_blogs_restore_data', 10, 1 ); -
trunk/tests/phpunit/testcases/blogs/functions.php
r9194 r9280 278 278 bp_blogs_add_blogmeta( 1, 'foo', 'bar' ); 279 279 $this->assertNotEmpty( bp_blogs_add_blogmeta( 1, 'foo', 'baz' ) ); 280 } 281 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 ) ); 295 $b2 = $this->factory->blog->create( array( 'user_id' => $u ) ); 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 ) ); 280 319 } 281 320
Note: See TracChangeset
for help on using the changeset viewer.