Ticket #5275: 5275.04.patch
File 5275.04.patch, 4.9 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 72a035d..fd9cdf5 100644
function bp_core_process_spammer_status( $user_id, $status, $do_wp_cleanup = tru 784 784 remove_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' ); 785 785 remove_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' ); 786 786 787 // Determine if we are on an admin page 788 $is_admin = is_admin(); 789 if ( $is_admin && ! defined( 'DOING_AJAX' ) ) { 790 $is_admin = (bool) ( buddypress()->members->admin->user_page !== get_current_screen()->id ); 791 } 792 793 // When marking as spam in the Dashboard, these actions are handled by WordPress 787 // force the cleanup of WordPress content and status for multisite configs 794 788 if ( $do_wp_cleanup ) { 795 789 796 790 // Get the blogs for the user … … function bp_core_process_spammer_status( $user_id, $status, $do_wp_cleanup = tru 811 805 if ( is_multisite() ) { 812 806 update_user_status( $user_id, 'spam', $is_spam ); 813 807 } 808 } 814 809 815 // Always set single sitestatus816 810 // Update the user status 811 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) ); 817 812 818 // Call multisite actions in single site mode for good measure 819 if ( !is_multisite() ) { 820 if ( true === $is_spam ) { 821 822 /** 823 * Fires at end of processing spammer in Dashboard if not multisite and user is spam. 824 * 825 * @since BuddyPress (1.5.0) 826 * 827 * @param int $value Displayed user ID. 828 */ 829 do_action( 'make_spam_user', bp_displayed_user_id() ); 830 } else { 813 // Clean user cache 814 clean_user_cache( $user_id ); 831 815 832 /** 833 * Fires at end of processing spammer in Dashboard if not multisite and user is not spam. 834 * 835 * @since BuddyPress (1.5.0) 836 * 837 * @param int $value Displayed user ID. 838 */ 839 do_action( 'make_ham_user', bp_displayed_user_id() ); 840 } 816 if ( ! is_multisite() ) { 817 // Call multisite actions in single site mode for good measure 818 if ( true === $is_spam ) { 841 819 820 /** 821 * Fires at end of processing spammer in Dashboard if not multisite and user is spam. 822 * 823 * @since BuddyPress (1.5.0) 824 * 825 * @param int $value user ID. 826 */ 827 do_action( 'make_spam_user', $user_id ); 828 } else { 842 829 830 /** 831 * Fires at end of processing spammer in Dashboard if not multisite and user is not spam. 832 * 833 * @since BuddyPress (1.5.0) 834 * 835 * @param int $value user ID. 836 */ 837 do_action( 'make_ham_user', $user_id ); 843 838 } 844 839 } 845 840 -
tests/phpunit/testcases/core/functions.php
diff --git tests/phpunit/testcases/core/functions.php tests/phpunit/testcases/core/functions.php index c279066..7430e4b 100644
class BP_Tests_Core_Functions extends BP_UnitTestCase { 648 648 date_default_timezone_set( $tz_backup ); 649 649 } 650 650 } 651 652 /** 653 * @group bp_core_process_spammer_status 654 */ 655 public function test_bp_core_process_spammer_status() { 656 if ( is_multisite() ) { 657 return; 658 } 659 660 $bp = buddypress(); 661 $displayed_user = $bp->displayed_user; 662 663 $u1 = $this->factory->user->create(); 664 $bp->displayed_user->id = $u1; 665 666 // Spam the user 667 bp_core_process_spammer_status( $u1, 'spam' ); 668 669 $this->assertTrue( bp_is_user_spammer( $u1 ) ); 670 671 // Unspam the user 672 bp_core_process_spammer_status( $u1, 'ham' ); 673 674 $this->assertFalse( bp_is_user_spammer( $u1 ) ); 675 676 // Reset displayed user 677 $bp->displayed_user = $displayed_user; 678 } 679 680 /** 681 * @group bp_core_process_spammer_status 682 */ 683 public function test_bp_core_process_spammer_status_ms_bulk_spam() { 684 if ( ! is_multisite() ) { 685 return; 686 } 687 688 $bp = buddypress(); 689 $displayed_user = $bp->displayed_user; 690 691 $u1 = $this->factory->user->create(); 692 $bp->displayed_user->id = $u1; 693 694 // Bulk spam in network admin uses update_user_status 695 update_user_status( $u1, 'spam', '1' ); 696 697 $this->assertTrue( bp_is_user_spammer( $u1 ) ); 698 699 // Unspam the user 700 bp_core_process_spammer_status( $u1, 'ham' ); 701 702 $this->assertFalse( bp_is_user_spammer( $u1 ) ); 703 704 // Reset displayed user 705 $bp->displayed_user = $displayed_user; 706 } 707 708 /** 709 * @group bp_core_process_spammer_status 710 */ 711 public function test_bp_core_process_spammer_status_ms_bulk_ham() { 712 if ( ! is_multisite() ) { 713 return; 714 } 715 716 $bp = buddypress(); 717 $displayed_user = $bp->displayed_user; 718 719 $u1 = $this->factory->user->create(); 720 $bp->displayed_user->id = $u1; 721 722 // Spam the user 723 bp_core_process_spammer_status( $u1, 'spam' ); 724 725 $this->assertTrue( bp_is_user_spammer( $u1 ) ); 726 727 // Bulk unspam in network admin uses update_user_status 728 update_user_status( $u1, 'spam', '0' ); 729 730 $this->assertFalse( bp_is_user_spammer( $u1 ) ); 731 732 // Reset displayed user 733 $bp->displayed_user = $displayed_user; 734 } 651 735 }