Skip to content

Commit 1ba4455

Browse files
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
1 parent 7fbabd5 commit 1ba4455

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/wp-includes/user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ function wp_insert_user( $userdata ) {
16651665

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
}
16711671

tests/phpunit/tests/user.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,34 @@ function test_wp_update_user_should_not_change_password_when_passed_WP_User_inst
574574
$this->assertEquals( $pwd_before, $pwd_after );
575575
}
576576

577+
/**
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+
577605
/**
578606
* @ticket 28315
579607
*/

0 commit comments

Comments
 (0)