Make WordPress Core

Changeset 45874


Ignore:
Timestamp:
08/22/2019 01:52:16 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Users: Adjust [45708] to make sure wp_update_user() does not issue a WP_Error if a single site was previously set up as Multisite and there's still a spam field in the user table.

Add a unit test.

Props azaozz, SergeyBiryukov.
Fixes #45747.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r45858 r45874  
    16661666    $user_activation_key = empty( $userdata['user_activation_key'] ) ? '' : $userdata['user_activation_key'];
    16671667
    1668     if ( isset( $userdata['spam'] ) && ! is_multisite() ) {
     1668    if ( ! empty( $userdata['spam'] ) && ! is_multisite() ) {
    16691669        return new WP_Error( 'no_spam', __( 'Sorry, marking a user as spam is only supported on Multisite.' ) );
    16701670    }
  • trunk/tests/phpunit/tests/user.php

    r45859 r45874  
    576576
    577577    /**
     578     * @ticket 45747
     579     */
     580    function test_wp_update_user_should_not_mark_user_as_spam_on_single_site() {
     581        if ( is_multisite() ) {
     582            $this->markTestSkipped( 'This test is intended for single site.' );
     583        }
     584
     585        $u = wp_update_user(
     586            array(
     587                'ID'   => self::$contrib_id,
     588                'spam' => '0',
     589            )
     590        );
     591
     592        $this->assertNotWPError( $u );
     593
     594        $u = wp_update_user(
     595            array(
     596                'ID'   => self::$contrib_id,
     597                'spam' => '1',
     598            )
     599        );
     600
     601        $this->assertWPError( $u );
     602        $this->assertSame( 'no_spam', $u->get_error_code() );
     603    }
     604
     605    /**
    578606     * @ticket 28315
    579607     */
Note: See TracChangeset for help on using the changeset viewer.