Skip to content

Commit 4a1978c

Browse files
authored
Merge pull request #499 from wp-cli/copilot/fix-network-activation-issue
Fix `--all --network` to network-activate single-site active plugins
2 parents 6cab094 + 70138bb commit 4a1978c

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

features/plugin.feature

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,44 @@ Feature: Manage WordPress plugins
298298
"""
299299
And the return code should be 0
300300

301+
@require-wp-5.2
302+
Scenario: Network activate all plugins when some are already active on a single site
303+
Given a WP multisite install
304+
And I run `wp plugin delete --all`
305+
306+
When I run `wp plugin install debug-bar`
307+
And I run `wp plugin install wordpress-importer --activate`
308+
Then STDOUT should contain:
309+
"""
310+
Plugin 'wordpress-importer' activated.
311+
"""
312+
313+
When I run `wp plugin list --fields=name,status`
314+
Then STDOUT should be a table containing rows:
315+
| name | status |
316+
| debug-bar | inactive |
317+
| wordpress-importer | active |
318+
319+
When I run `wp plugin activate --all --network`
320+
Then STDOUT should contain:
321+
"""
322+
Plugin 'debug-bar' network activated.
323+
"""
324+
And STDOUT should contain:
325+
"""
326+
Plugin 'wordpress-importer' network activated.
327+
"""
328+
And STDOUT should contain:
329+
"""
330+
Success: Network activated 2 of 2 plugins.
331+
"""
332+
333+
When I run `wp plugin list --fields=name,status`
334+
Then STDOUT should be a table containing rows:
335+
| name | status |
336+
| debug-bar | active-network |
337+
| wordpress-importer | active-network |
338+
301339
Scenario: List plugins
302340
Given a WP install
303341

src/Plugin_Command.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ public function activate( $args, $assoc_args = [] ) {
383383
}
384384
foreach ( $plugins as $plugin ) {
385385
$status = $this->get_status( $plugin->file );
386-
if ( $all && ! $force && in_array( $status, [ 'active', 'active-network' ], true ) ) {
386+
// When using --all flag, skip plugins that are already in the target state.
387+
$skip_statuses = $network_wide ? array( 'active-network' ) : array( 'active', 'active-network' );
388+
if ( $all && ! $force && in_array( $status, $skip_statuses, true ) ) {
387389
continue;
388390
}
389391
// Network-active is the highest level of activation status.

0 commit comments

Comments
 (0)