From 1ba44554be3ca18eecd87bf58ef784a7310240f9 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 22 Aug 2019 01:52:16 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@45874 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/user.php | 2 +- tests/phpunit/tests/user.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index f43f5e9a94..069e1c9ee7 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -1665,7 +1665,7 @@ function wp_insert_user( $userdata ) { $user_activation_key = empty( $userdata['user_activation_key'] ) ? '' : $userdata['user_activation_key']; - if ( isset( $userdata['spam'] ) && ! is_multisite() ) { + if ( ! empty( $userdata['spam'] ) && ! is_multisite() ) { return new WP_Error( 'no_spam', __( 'Sorry, marking a user as spam is only supported on Multisite.' ) ); } diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index faf6798ba7..d90793958b 100644 --- a/tests/phpunit/tests/user.php +++ b/tests/phpunit/tests/user.php @@ -574,6 +574,34 @@ class Tests_User extends WP_UnitTestCase { $this->assertEquals( $pwd_before, $pwd_after ); } + /** + * @ticket 45747 + */ + function test_wp_update_user_should_not_mark_user_as_spam_on_single_site() { + if ( is_multisite() ) { + $this->markTestSkipped( 'This test is intended for single site.' ); + } + + $u = wp_update_user( + array( + 'ID' => self::$contrib_id, + 'spam' => '0', + ) + ); + + $this->assertNotWPError( $u ); + + $u = wp_update_user( + array( + 'ID' => self::$contrib_id, + 'spam' => '1', + ) + ); + + $this->assertWPError( $u ); + $this->assertSame( 'no_spam', $u->get_error_code() ); + } + /** * @ticket 28315 */