Ticket #5275: 5275.05.patch
File 5275.05.patch, 5.1 KB (added by , 10 years ago) |
---|
-
src/bp-members/bp-members-functions.php
diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php index eab418d..b1fddd2 100644
function bp_core_process_spammer_status( $user_id, $status, $do_wp_cleanup = tru 785 785 remove_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' ); 786 786 remove_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' ); 787 787 788 // Determine if we are on an admin page 789 $is_admin = is_admin(); 790 if ( $is_admin && ! defined( 'DOING_AJAX' ) ) { 791 $is_admin = (bool) ( buddypress()->members->admin->user_page !== get_current_screen()->id ); 792 } 793 794 // When marking as spam in the Dashboard, these actions are handled by WordPress 788 // force the cleanup of WordPress content and status for multisite configs 795 789 if ( $do_wp_cleanup ) { 796 790 797 791 // Get the blogs for the user … … function bp_core_process_spammer_status( $user_id, $status, $do_wp_cleanup = tru 812 806 if ( is_multisite() ) { 813 807 update_user_status( $user_id, 'spam', $is_spam ); 814 808 } 809 } 815 810 816 // Always set single sitestatus817 811 // Update the user status 812 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) ); 818 813 819 // Call multisite actions in single site mode for good measure 820 if ( !is_multisite() ) { 821 if ( true === $is_spam ) { 822 823 /** 824 * Fires at end of processing spammer in Dashboard if not multisite and user is spam. 825 * 826 * @since BuddyPress (1.5.0) 827 * 828 * @param int $value Displayed user ID. 829 */ 830 do_action( 'make_spam_user', bp_displayed_user_id() ); 831 } else { 814 // Clean user cache 815 clean_user_cache( $user_id ); 832 816 833 /** 834 * Fires at end of processing spammer in Dashboard if not multisite and user is not spam. 835 * 836 * @since BuddyPress (1.5.0) 837 * 838 * @param int $value Displayed user ID. 839 */ 840 do_action( 'make_ham_user', bp_displayed_user_id() ); 841 } 817 if ( ! is_multisite() ) { 818 // Call multisite actions in single site mode for good measure 819 if ( true === $is_spam ) { 842 820 821 /** 822 * Fires at end of processing spammer in Dashboard if not multisite and user is spam. 823 * 824 * @since BuddyPress (1.5.0) 825 * 826 * @param int $value user ID. 827 */ 828 do_action( 'make_spam_user', $user_id ); 829 } else { 843 830 831 /** 832 * Fires at end of processing spammer in Dashboard if not multisite and user is not spam. 833 * 834 * @since BuddyPress (1.5.0) 835 * 836 * @param int $value user ID. 837 */ 838 do_action( 'make_ham_user', $user_id ); 844 839 } 845 840 } 846 841 -
tests/phpunit/testcases/members/functions.php
diff --git tests/phpunit/testcases/members/functions.php tests/phpunit/testcases/members/functions.php index c8b3d2a..185b332 100644
class BP_Tests_Members_Functions extends BP_UnitTestCase { 450 450 /** 451 451 * @group bp_core_process_spammer_status 452 452 */ 453 public function test_bp_core_process_spammer_status() { 454 if ( is_multisite() ) { 455 return; 456 } 457 458 $bp = buddypress(); 459 $displayed_user = $bp->displayed_user; 460 461 $u1 = $this->factory->user->create(); 462 $bp->displayed_user->id = $u1; 463 464 // Spam the user 465 bp_core_process_spammer_status( $u1, 'spam' ); 466 467 $this->assertTrue( bp_is_user_spammer( $u1 ) ); 468 469 // Unspam the user 470 bp_core_process_spammer_status( $u1, 'ham' ); 471 472 $this->assertFalse( bp_is_user_spammer( $u1 ) ); 473 474 // Reset displayed user 475 $bp->displayed_user = $displayed_user; 476 } 477 478 /** 479 * @group bp_core_process_spammer_status 480 */ 481 public function test_bp_core_process_spammer_status_ms_bulk_spam() { 482 if ( ! is_multisite() ) { 483 return; 484 } 485 486 $bp = buddypress(); 487 $displayed_user = $bp->displayed_user; 488 489 $u1 = $this->factory->user->create(); 490 $bp->displayed_user->id = $u1; 491 492 // Bulk spam in network admin uses update_user_status 493 update_user_status( $u1, 'spam', '1' ); 494 495 $this->assertTrue( bp_is_user_spammer( $u1 ) ); 496 497 // Unspam the user 498 bp_core_process_spammer_status( $u1, 'ham' ); 499 500 $this->assertFalse( bp_is_user_spammer( $u1 ) ); 501 502 // Reset displayed user 503 $bp->displayed_user = $displayed_user; 504 } 505 506 /** 507 * @group bp_core_process_spammer_status 508 */ 509 public function test_bp_core_process_spammer_status_ms_bulk_ham() { 510 if ( ! is_multisite() ) { 511 return; 512 } 513 514 $bp = buddypress(); 515 $displayed_user = $bp->displayed_user; 516 517 $u1 = $this->factory->user->create(); 518 $bp->displayed_user->id = $u1; 519 520 // Spam the user 521 bp_core_process_spammer_status( $u1, 'spam' ); 522 523 $this->assertTrue( bp_is_user_spammer( $u1 ) ); 524 525 // Bulk unspam in network admin uses update_user_status 526 update_user_status( $u1, 'spam', '0' ); 527 528 $this->assertFalse( bp_is_user_spammer( $u1 ) ); 529 530 // Reset displayed user 531 $bp->displayed_user = $displayed_user; 532 } 533 534 /** 535 * @group bp_core_process_spammer_status 536 */ 453 537 public function test_bp_core_process_spammer_status_make_spam_user_filter() { 454 538 add_filter( 'make_spam_user', array( $this, 'notification_filter_callback' ) ); 455 539