Fix plugin deactivation during force install with explicit --activate flag#500
Open
Fix plugin deactivation during force install with explicit --activate flag#500
Conversation
When using `wp plugin install --force --activate`, the plugin should always be activated even if it appears to be already active. This fixes an edge case where WordPress might deactivate a plugin during the installation process (when plugin files are temporarily deleted), leaving the plugin deactivated after the update completes. The fix modifies the activate() method to skip the "already active" check when called from the install command (chained_command = true), ensuring that explicit activation requests are always honored. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
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>
Copilot
AI
changed the title
[WIP] Fix plugin deactivation issue after updating with zip file
Fix plugin deactivation during force install with explicit --activate flag
Feb 12, 2026
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
When activate() is called from install command and the plugin is
already active, activate_plugin() returns WP_Error('plugin_already_active').
This should be treated as success, not failure, since the desired end
state (active plugin) is achieved.
Changes:
- Restructure activation checks to always run force deactivation first
- When chained_command is true and plugin is already active without force,
fall through to activate_plugin() and handle 'plugin_already_active' error
- Treat 'plugin_already_active' as success when called from install command
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Replace --force tests with tests that actually exercise the code path where activate_plugin() returns 'plugin_already_active'. These tests verify that installing an already-active plugin with --activate (without --force) correctly treats the 'plugin_already_active' error as success. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Successfully addressed all review feedback from @copilot-pull-request-reviewer[bot]:
Code Changes (commits 1b639da and c13bbd5)
Problem: When
activate()is called from install command and the plugin is already active,activate_plugin()returnsWP_Error('plugin_already_active'), which was treated as a failure.Solution:
Restructured activation logic (lines 389-410):
--forceflag always deactivates before reactivating (runs activation hooks)chained_commandstate--forceandchained_commandis true, fall through toactivate_plugin()Handle 'plugin_already_active' error (lines 419-425):
chained_command = true)activate_plugin()returnsWP_Error('plugin_already_active')Test Changes (commit c13bbd5)
Previous tests: Used
--force --activatewhich doesn't exercise the fix (force always deactivates first)Updated tests: Install already-active plugins with
--activate(no--force):wp plugin install hello-dolly --activateon already-active pluginwp plugin install hello-dolly --activate-networkon already-network-active pluginactivate_plugin()returns 'plugin_already_active'Verification
✅ All linting checks pass
✅ Code style (phpcs) passes
✅ Static analysis (phpstan) passes
✅ Replied to all review comments
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.