Ticket #8316: 8316.01.patch
| File 8316.01.patch, 3.1 KB (added by , 6 years ago) |
|---|
-
src/bp-members/bp-members-functions.php
696 696 // Force the cleanup of WordPress content and status for multisite configs. 697 697 if ( $do_wp_cleanup ) { 698 698 699 // Get the blogs for the user. 700 $blogs = get_blogs_of_user( $user_id, true ); 699 // Mark blogs as spam if the user is the sole admin of a site. 700 if ( is_multisite() ) { 701 /* 702 * No native function to fetch a user's blogs by role, so do it manually. 703 * 704 * This logic is mostly copied from get_blogs_of_user(). 705 */ 706 $meta = get_user_meta( $user_id ); 701 707 702 foreach ( (array) array_values( $blogs ) as $details ) { 708 foreach ( $meta as $key => $val ) { 709 if ( 'capabilities' !== substr( $key, -12 ) ) { 710 continue; 711 } 712 if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) { 713 continue; 714 } 715 $site_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); 716 if ( ! is_numeric( $site_id ) ) { 717 continue; 718 } 703 719 704 // Do not mark the main or current root blog as spam. 705 if ( 1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id ) { 706 continue; 707 } 720 $site_id = (int) $site_id; 708 721 709 // Update the blog status. 710 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 722 // Do not mark the main or current root blog as spam. 723 if ( 1 === $site_id || bp_get_root_blog_id() === $site_id ) { 724 continue; 725 } 726 727 // Now, do check for administrator role. 728 $role = maybe_unserialize( $val ); 729 if ( empty( $role['administrator'] ) ) { 730 continue; 731 } 732 733 // Check if the site has more than 1 admin. If so, bail. 734 $counts = count_users( 'time', $site_id ); 735 if ( $counts['avail_roles']['administrator'] > 1 ) { 736 continue; 737 } 738 739 // Now we can spam the blog. 740 update_blog_status( $site_id, 'spam', $is_spam ); 741 } 711 742 } 712 743 713 744 // Finally, mark this user as a spammer. -
tests/phpunit/testcases/members/functions.php
539 539 540 540 } 541 541 542 /** 543 * @group bp_core_process_spammer_status 544 * @ticket BP8316 545 */ 546 public function test_bp_core_process_spammer_status_ms_should_only_spam_sites_with_one_admin() { 547 if ( ! is_multisite() ) { 548 $this->markTestSkipped(); 549 } 550 551 $u1 = self::factory()->user->create(); 552 $u2 = self::factory()->user->create(); 553 554 $b1 = self::factory()->blog->create( array( 'user_id' => $u1 ) ); 555 556 // Add user 2 to site as administrator. 557 add_user_to_blog( $b1, $u2, 'administrator' ); 558 559 // Mark user 2 as a spammer. 560 bp_core_process_spammer_status( $u2, 'spam' ); 561 562 // Ensure site isn't marked as spam because there is more than one admin. 563 $site = get_site( $b1 ); 564 $this->assertEmpty( $site->spam ); 565 } 566 542 567 public function notification_filter_callback( $value ) { 543 568 $this->filter_fired = current_filter(); 544 569 return $value;
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)