Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 14, 2025

Description

When a plugin directory is manually removed (not via WP-CLI), the plugin remains in WordPress's active_plugins option. This orphaned entry can break dependency checks and compatibility features in other plugins and core. wp plugin is-active previously returned "not active" without indicating this inconsistent state.

Changes

  • Modified Plugin_Command::is_active() to check active_plugins / active_sitewide_plugins options when plugin file is not found
  • Uses WordPress's validate_plugin() to confirm file absence
  • Emits warning: Plugin 'X' is marked as active but the plugin file does not exist.
  • Returns exit code 1 (not active) as before - no behavioral change
  • Handles both single-site and multisite scenarios

Example behavior:

$ wp plugin activate akismet
Success: Activated 1 of 1 plugins.

$ rm -rf wp-content/plugins/akismet

$ wp plugin is-active akismet
Warning: Plugin 'akismet' is marked as active but the plugin file does not exist.
$ echo $?
1

Tests

  • Added features/plugin-is-active.feature with scenarios covering active, inactive, missing, and orphaned plugins
  • Includes test for network-activated plugins with missing files to verify --network flag behavior
  • Fixed test scenario to properly activate plugin before deactivating to ensure consistent test behavior

Checklist

  • Functional tests included
  • Follows WP-CLI coding standards (lint, phpcs, phpstan pass)
  • Documentation updated (method docblock)
Original prompt

This section details on the original issue you should resolve

<issue_title>is-active/deactivate should also check the "active_plugins" option</issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior

When a plugin file/directory is removed by the user (and not by WP), the "active_plugins" option will still contain that plugin.
Various plugins (and WP core?) use this "active_plugins" option for dependency checks, loading of compatibitility data,...

However wp plugin is-active and wp plugin deactivate will report that the plugin isn't active/the plugin could not be found.

WP core has a function https://developer.wordpress.org/reference/functions/validate_active_plugins/ to update this option (and deactivate all those not found ones), however it will deactivate ALL of those plugins, not necessarily only the one passed to CLI. However it's trivial copy and port that to CLI.

Describe how other contributors can replicate this bug

wp plugin activate whatever
rm -rf wp-content/plugins/whatever
wp plugin deactivate whatever
wp eval "echo array_values( preg_grep( '#^whatever#', get_option( 'active_plugins' ) ) )[0];"

Describe what you would expect as the correct outcome

is-active and deactivate should deactivate the plugin if it's still in active_plugins but the directory does not exist.

Provide a possible solution

See validate_active_plugins()</issue_description>

<agent_instructions>wp plugin is-active should emit a warning if the plugin does not exist but is still in the active_plugins option. This can be done by using the validate_plugin option provided by WordPress</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@swissspidy Updating `wp plugin deactivate` sounds reasonable at first glance, but we shouldn't change `is-active` to make destructive actions. That sounds very unexpected when you just want to check the status. @swissspidy What about `wp plugin is-active` emitting a warning if the plugin does not exist but is still in the `active_plugins` option?

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix is-active/deactivate to check active_plugins option Add warning in wp plugin is-active for missing plugin files still in active_plugins Dec 14, 2025
Copilot AI requested a review from swissspidy December 14, 2025 21:09
@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a warning message when wp plugin is-active is run on a plugin that has been manually removed from the filesystem but remains in WordPress's active_plugins or active_sitewide_plugins option. This orphaned state can cause issues with dependency checks and compatibility features in other plugins and WordPress core.

Key Changes

  • Modified Plugin_Command::is_active() to detect orphaned plugin entries by checking the active plugins options when the plugin file is not found
  • Uses WordPress's validate_plugin() function to confirm the file is truly missing (and not just filtered)
  • Emits a helpful warning message while maintaining the existing exit code 1 behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/Plugin_Command.php Added logic to check active_plugins/active_sitewide_plugins options when plugin is not found via fetcher, and emit warning if plugin file doesn't exist but is still marked as active
features/plugin-is-active.feature New test file with scenarios covering active, inactive, missing, and orphaned plugins to verify the warning behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@swissspidy swissspidy marked this pull request as ready for review December 14, 2025 22:03
@swissspidy swissspidy requested a review from a team as a code owner December 14, 2025 22:03
@codecov
Copy link

codecov bot commented Dec 14, 2025

Codecov Report

❌ Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Plugin_Command.php 0.00% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions bot added command:plugin-is-active Related to 'plugin is-active' command scope:documentation Related to documentation labels Dec 22, 2025
@github-actions github-actions bot added the scope:testing Related to testing label Dec 22, 2025
@swissspidy swissspidy added this to the 2.3.0 milestone Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:plugin-is-active Related to 'plugin is-active' command scope:documentation Related to documentation scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

is-active/deactivate should also check the "active_plugins" option

2 participants