Skip to content

Commit 5305959

Browse files
Copilotswissspidy
andcommitted
Add tests for plugin activation with --force flag
Add comprehensive tests to verify that plugins remain activated when using --force with --activate or --activate-network flags. These tests cover both single-site and multisite scenarios. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 1cd40e6 commit 5305959

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

features/plugin-install.feature

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,36 @@ Feature: Install WordPress plugins
338338
"""
339339
active
340340
"""
341+
342+
Scenario: Force update a network-active plugin with --activate-network flag should keep it network-activated
343+
Given a WP multisite install
344+
345+
When I run `wp plugin install hello-dolly --activate-network`
346+
Then STDOUT should contain:
347+
"""
348+
Plugin 'hello-dolly' network activated.
349+
"""
350+
And the return code should be 0
351+
352+
When I run `wp plugin list --name=hello-dolly --field=status`
353+
Then STDOUT should be:
354+
"""
355+
active-network
356+
"""
357+
358+
When I run `wp plugin install hello-dolly --force --activate-network`
359+
Then STDOUT should contain:
360+
"""
361+
Plugin updated successfully
362+
"""
363+
And STDOUT should contain:
364+
"""
365+
Success: Installed 1 of 1 plugins.
366+
"""
367+
And the return code should be 0
368+
369+
When I run `wp plugin list --name=hello-dolly --field=status`
370+
Then STDOUT should be:
371+
"""
372+
active-network
373+
"""

src/Plugin_Command.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ public function activate( $args, $assoc_args = [] ) {
378378
continue;
379379
}
380380
// Network-active is the highest level of activation status.
381-
if ( 'active-network' === $status ) {
381+
// However, when called from install command (chained_command), always attempt activation
382+
// to handle edge cases where the plugin may have been deactivated during the install process.
383+
if ( 'active-network' === $status && ! $this->chained_command ) {
382384
WP_CLI::warning( "Plugin '{$plugin->name}' is already network active." );
383385
continue;
384386
}

0 commit comments

Comments
 (0)