Fix: Plugin dependencies: better messaging or management of plugin active states - #12732
Fix: Plugin dependencies: better messaging or management of plugin active states#12732hbhalodia wants to merge 3 commits into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.' );
There was a problem hiding this comment.
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_dependencyis 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.' );
}
Trac ticket: https://core.trac.wordpress.org/ticket/64493
Use of AI Tools
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:
This is wrong in two ways:
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()):Note: This plugin cannot be deactivated until the plugins that require it are deactivated.Note: 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":
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.