Skip to content

Fix: Plugin dependencies: better messaging or management of plugin active states - #12732

Open
hbhalodia wants to merge 3 commits into
WordPress:trunkfrom
hbhalodia:fix/issue-64493
Open

Fix: Plugin dependencies: better messaging or management of plugin active states#12732
hbhalodia wants to merge 3 commits into
WordPress:trunkfrom
hbhalodia:fix/issue-64493

Conversation

@hbhalodia

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/64493

Use of AI Tools

  • Claude Code, Opus 5
  • Used on inital implementation and drafting the message and PR description. Final implementation reviwed by me and tested in local env.

AI Summary

The "Required by" note on the Plugins screen uses a single static message that doesn't match reality. This change generates it from the plugin's current state so it reflects the action that's actually available.

Problem

For any plugin with dependents, the note always reads:

Note: This plugin cannot be deactivated or deleted until the plugins that require it are deactivated or deleted.

This is wrong in two ways:

  1. Deletion — a dependent must be deleted; deactivating it is not sufficient. So "deactivated or deleted" is inaccurate.
  2. State — the message never changes. It claims a plugin "cannot be deactivated" even when it has no active dependents (deactivation is actually allowed), or when the plugin is already inactive. It also mentions deletion for active plugins, which can't be deleted anyway (Delete is only offered for inactive plugins).

Fix

The note in WP_Plugins_List_Table::add_dependents_to_dependency_plugin_row() now branches on the plugin's active state, using the same signals that gate the action links (is_plugin_active() / has_active_dependents()):

  • Active plugin, with an active dependentNote: This plugin cannot be deactivated until the plugins that require it are deactivated.
  • Active plugin, no active dependents → no note (deactivation is allowed).
  • Inactive pluginNote: This plugin cannot be deleted until the plugins that require it are deleted.

The message is also now rendered as an inline admin notice via wp_get_admin_notice() (type => 'error', additional_classes => array( 'inline' )) instead of a plain paragraph, so it's styled consistently with other admin notices.

When there is no applicable restriction, no notice is output.

Example

Plugin "Example Dependency" is required by "Example Dependent One":

Scenario Old note New note
Both active cannot be deactivated or deleted until … deactivated or deleted cannot be deactivated until … deactivated
Dependency active, dependent inactive (same wrong message) (no note — deactivation is allowed)
Dependency inactive (same wrong message) cannot be deleted until … deleted

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copilot AI review requested due to automatic review settings July 28, 2026 09:38
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props hbhalodia.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

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 updates how the Plugins screen communicates dependency restrictions (“Required by”) so the message reflects the dependency plugin’s current state and the action that is actually restricted, and renders the message using standard inline admin notice styling.

Changes:

  • Branch the dependency restriction message based on whether the dependency plugin is active and whether it has active dependents.
  • Replace the static paragraph note with an inline admin notice generated via wp_get_admin_notice().
  • Adjust the “Required by” row markup to accommodate the notice HTML.

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

Comment thread src/wp-admin/includes/class-wp-plugins-list-table.php Outdated
Copilot AI review requested due to automatic review settings July 28, 2026 10:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/wp-admin/includes/class-wp-plugins-list-table.php:1636

  • The non-network-admin branch only runs when the dependency plugin is active, which means (a) inactive dependency plugins on single-site never get the intended “cannot be deleted…” notice, and (b) active single-site plugins with no active dependents can incorrectly get a delete-related note even though active plugins can’t be deleted from the Plugins screen. This contradicts the action-link gating in single_row() and the intended behavior described in the PR.
		} elseif ( is_plugin_active( $dependency ) ) {
			if ( WP_Plugin_Dependencies::has_active_dependents( $dependency ) ) {
				$dependency_note = __( 'Note: This plugin cannot be deactivated until the plugins that require it are deactivated.' );
			} elseif ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
				$dependency_note = __( 'Note: This plugin cannot be deleted until the plugins that require it are deleted.' );

Copilot AI review requested due to automatic review settings July 28, 2026 10:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

src/wp-admin/includes/class-wp-plugins-list-table.php:1639

  • Same as the network-admin branch: the delete-restriction note should respect circular dependencies. single_row() enables Delete when $has_circular_dependency is true (see ~:1053), but this note would still say the plugin cannot be deleted. Add a circular-dependency check so the note only appears when deletion is actually blocked.
			if ( $is_active && current_user_can( 'deactivate_plugin', $dependency ) && WP_Plugin_Dependencies::has_active_dependents( $dependency ) ) {
				$dependency_note = __( 'Note: This plugin cannot be deactivated until the plugins that require it are deactivated.' );
			} elseif ( ! $is_active && ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
				$dependency_note = __( 'Note: This plugin cannot be deleted until the plugins that require it are deleted.' );
			}

src/wp-admin/includes/class-wp-plugins-list-table.php:1631

  • The delete-restriction note doesn’t account for circular dependencies. In single_row(), the Delete action is only disabled when $has_dependents && ! $has_circular_dependency (see ~:947), but this note will still claim the plugin “cannot be deleted…” even when a circular dependency exists and deletion is allowed. Consider aligning the note condition with the action link gating by skipping the note when there is a circular dependency.

This issue also appears on line 1635 of the same file.

			if ( $is_network_active && current_user_can( 'manage_network_plugins' ) && WP_Plugin_Dependencies::has_active_dependents( $dependency ) ) {
				$dependency_note = __( 'Note: This plugin cannot be deactivated until the plugins that require it are deactivated.' );
			} elseif ( ! $is_network_active && ! is_plugin_active( $dependency ) && current_user_can( 'delete_plugins' ) ) {
				$dependency_note = __( 'Note: This plugin cannot be deleted until the plugins that require it are deleted.' );
			}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants