Skip to content

Commit 9d217ac

Browse files
Copilotswissspidy
andcommitted
Fix --all --network flag to properly network-activate single-site active plugins
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent a1d37e3 commit 9d217ac

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

features/plugin.feature

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

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

src/Plugin_Command.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ public function activate( $args, $assoc_args = [] ) {
374374
}
375375
foreach ( $plugins as $plugin ) {
376376
$status = $this->get_status( $plugin->file );
377-
if ( $all && in_array( $status, [ 'active', 'active-network' ], true ) ) {
377+
// When using --all flag, skip plugins that are already in the target state.
378+
// For --all --network, only skip plugins that are already network-active.
379+
// For --all without --network, only skip plugins that are already active.
380+
if ( $all && ( ( $network_wide && 'active-network' === $status ) || ( ! $network_wide && 'active' === $status ) ) ) {
378381
continue;
379382
}
380383
// Network-active is the highest level of activation status.

0 commit comments

Comments
 (0)