Skip to:
Content

BuddyPress.org

Changeset 9398


Ignore:
Timestamp:
01/22/2015 01:31:56 PM (12 years ago)
Author:
imath
Message:

On multisite configs, make sure unspamming the user from the Users Network Administration screen is updating the .

When a user is marked as spam from the front end, then marked as ham from the network-users administration screen using the 'unspam' bulk action, we need to be sure the field of the users table is updated so that BuddyPress effectively takes in account the user has been unspammed.

This commit also makes sure the user's cache has been cleared.

Fixes #5275

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r9371 r9398  
    786786        remove_action( 'make_ham_user',  'bp_core_mark_user_ham_admin'  );
    787787
    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
    795789        if ( $do_wp_cleanup ) {
    796790
     
    813807                        update_user_status( $user_id, 'spam', $is_spam );
    814808                }
    815 
    816                 // Always set single site status
    817                 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) );
    818 
     809        }
     810
     811        // Update the user status
     812        $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) );
     813
     814        // Clean user cache
     815        clean_user_cache( $user_id );
     816
     817        if ( ! is_multisite() ) {
    819818                // 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 {
    832 
    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                         }
    842 
    843 
     819                if ( true === $is_spam ) {
     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 {
     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 );
    844839                }
    845840        }
  • trunk/tests/phpunit/testcases/members/functions.php

    r9336 r9398  
    451451         * @group bp_core_process_spammer_status
    452452         */
     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         */
    453537        public function test_bp_core_process_spammer_status_make_spam_user_filter() {
    454538                add_filter( 'make_spam_user', array( $this, 'notification_filter_callback' ) );
Note: See TracChangeset for help on using the changeset viewer.