Add --force flag to plugin activate to re-run activation hooks #496
+141
−6
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
This PR adds a
--forceflag towp plugin activatecommand that forces re-running activation hooks even if the plugin is already active. When both--activateand--forceflags are used withwp plugin install, the force behavior is passed through to the activate command.Implementation Checklist
--forceflag towp plugin activatecommand that forces re-running activation hooks--forceflagactivate()method to check for the--forceflag--forceis set and plugin is already active, deactivate then reactivate to trigger hookswp plugin installto pass--forceto activate when both flags are presentwp plugin activate --forceon an already active pluginwp plugin install --activate --forceon an already installed and active pluginUse Case
This is particularly useful when a plugin is activated but in a weird state. For example, WP Super Cache installs an
advanced-cache.phpdropin when activated. If that file gets deleted, the plugin remains activated but doesn't work properly. Runningwp plugin install wp-super-cache --activate --forcewill now re-run the activation hooks and recreate the dropin file.Files Changed
src/Plugin_Command.php: Added--forceflag handling toactivate()methodsrc/WP_CLI/CommandWithUpgrade.php: Modifiedinstall()to pass force flag to activatefeatures/plugin-activate.feature: Added test for force activatefeatures/plugin-install.feature: Added test for install with activate and forceTotal changes: 4 files changed, 134 insertions(+), 6 deletions(-)
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.