Skip to content

Commit 694a4a5

Browse files
Do not mark main site as spam when using 'wp user spam' (#393)
* Do not mark main site as spam when using 'wp user spam'. * Remove unnecessary use of WP_CLI\Fetchers\Site. * Pass network ID to is_main_site() check in 'wp user spam' command. Addendum to commit 1bc55d0. * Add tests for blog spam/unspam behaviors --------- Co-authored-by: Daniel Bachhuber <[email protected]>
1 parent 132dd6a commit 694a4a5

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

features/user.feature

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ Feature: Manage WordPress users
435435
And I run `wp user get oprime`
436436
Then STDOUT should not be empty
437437

438+
When I run `wp site create --slug=foo --porcelain`
439+
Then save STDOUT as {SPAM_SITE_ID}
440+
441+
When I run `wp --url=example.com/foo user set-role {BBEE_ID} administrator`
442+
Then STDOUT should contain:
443+
"""
444+
Success:
445+
"""
446+
438447
When I run `wp user spam {BBEE_ID}`
439448
Then STDOUT should be:
440449
"""
@@ -453,6 +462,18 @@ Feature: Manage WordPress users
453462
"""
454463
And the return code should be 0
455464

465+
When I run `wp site list --site__in=1 --field=spam`
466+
Then STDOUT should be:
467+
"""
468+
0
469+
"""
470+
471+
When I run `wp site list --site__in={SPAM_SITE_ID} --field=spam`
472+
Then STDOUT should be:
473+
"""
474+
1
475+
"""
476+
456477
When I try `wp user spam {OP_ID} 9999`
457478
Then STDOUT should be:
458479
"""
@@ -466,6 +487,24 @@ Feature: Manage WordPress users
466487
"""
467488
And the return code should be 1
468489

490+
When I run `wp user unspam {BBEE_ID}`
491+
Then STDOUT should contain:
492+
"""
493+
Success:
494+
"""
495+
496+
When I run `wp site list --site__in=1 --field=spam`
497+
Then STDOUT should be:
498+
"""
499+
0
500+
"""
501+
502+
When I run `wp site list --site__in={SPAM_SITE_ID} --field=spam`
503+
Then STDOUT should be:
504+
"""
505+
0
506+
"""
507+
469508
@require-wp-4.3
470509
Scenario: Sending emails on update
471510
Given a WP install

src/User_Command.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use WP_CLI\CommandWithDBObject;
44
use WP_CLI\Entity\Utils as EntityUtils;
5-
use WP_CLI\Fetchers\Site as SiteFetcher;
65
use WP_CLI\Fetchers\User as UserFetcher;
76
use WP_CLI\Formatter;
87
use WP_CLI\Iterators\CSV as CsvIterator;
@@ -51,8 +50,7 @@ class User_Command extends CommandWithDBObject {
5150
];
5251

5352
public function __construct() {
54-
$this->fetcher = new UserFetcher();
55-
$this->sitefetcher = new SiteFetcher();
53+
$this->fetcher = new UserFetcher();
5654
}
5755

5856
/**
@@ -1251,10 +1249,8 @@ private function update_msuser_status( $user_ids, $pref, $value ) {
12511249
// Make that user's blog as spam too.
12521250
$blogs = (array) get_blogs_of_user( $user_id, true );
12531251
foreach ( $blogs as $details ) {
1254-
$site = $this->sitefetcher->get_check( $details->site_id );
1255-
1256-
// Main blog shouldn't a spam !
1257-
if ( $details->userblog_id !== $site->blog_id ) {
1252+
// Only mark site as spam if not main site.
1253+
if ( ! is_main_site( $details->userblog_id, $details->site_id ) ) {
12581254
update_blog_status( $details->userblog_id, $pref, $value );
12591255
}
12601256
}

0 commit comments

Comments
 (0)