From 20e57dca02de93075b4849aebc49f23077a1bfc2 Mon Sep 17 00:00:00 2001 From: desrosj Date: Tue, 5 Mar 2024 06:27:09 +0000 Subject: [PATCH] Plugins: Improve plugin dependency admin notices. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes several refinements to the various notices displayed in the WordPress admin related to plugin dependencies. Additionally, it adds some conditions to display more appropriate messages for multisite installs with proper context to the user’s capabilities. Props costdev, joedolson, afragen, swissspidy, peterwilsoncc, euthelup. Fixes #60465. Built from https://develop.svn.wordpress.org/trunk@57769 git-svn-id: http://core.svn.wordpress.org/trunk@57270 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-plugins-list-table.php | 26 +++++++++++++++---- wp-includes/class-wp-plugin-dependencies.php | 24 +++++++++++++++-- wp-includes/version.php | 2 +- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index 4777a8edcf..4cc0132b6f 100644 --- a/wp-admin/includes/class-wp-plugins-list-table.php +++ b/wp-admin/includes/class-wp-plugins-list-table.php @@ -1567,19 +1567,35 @@ class WP_Plugins_List_Table extends WP_List_Table { $links[] = $this->get_dependency_view_details_link( $name, $slug ); } - $dependency_note = __( 'Note: This plugin cannot be activated until the plugins that are required by it are activated.' ); - - $comma = wp_get_list_item_separator(); - $requires = sprintf( + $is_active = is_multisite() ? is_plugin_active_for_network( $dependent ) : is_plugin_active( $dependent ); + $comma = wp_get_list_item_separator(); + $requires = sprintf( /* translators: %s: List of dependency names. */ __( 'Requires: %s' ), implode( $comma, $links ) ); + $notice = ''; + $error_message = ''; + if ( WP_Plugin_Dependencies::has_unmet_dependencies( $dependent ) ) { + if ( $is_active ) { + $error_message = __( 'This plugin is active but may not function correctly because required plugins are missing or inactive.' ); + } else { + $error_message = __( 'This plugin cannot be activated because required plugins are missing or inactive.' ); + } + $notice = wp_get_admin_notice( + $error_message, + array( + 'type' => 'error', + 'additional_classes' => array( 'inline', 'notice-alt' ), + ) + ); + } + printf( '

%1$s

%2$s

', $requires, - $dependency_note + $notice ); } diff --git a/wp-includes/class-wp-plugin-dependencies.php b/wp-includes/class-wp-plugin-dependencies.php index 645285a7c0..77444f33d1 100644 --- a/wp-includes/class-wp-plugin-dependencies.php +++ b/wp-includes/class-wp-plugin-dependencies.php @@ -369,10 +369,30 @@ class WP_Plugin_Dependencies { */ public static function display_admin_notice_for_unmet_dependencies() { if ( in_array( false, self::get_dependency_filepaths(), true ) ) { + $error_message = __( 'Some required plugins are missing or inactive.' ); + + if ( is_multisite() ) { + if ( current_user_can( 'manage_network_plugins' ) ) { + $error_message .= ' ' . sprintf( + /* translators: %s: Link to the network plugins page. */ + __( 'Manage plugins.' ), + esc_url( network_admin_url( 'plugins.php' ) ) + ); + } else { + $error_message .= ' ' . __( 'Please contact your network administrator.' ); + } + } elseif ( 'plugins' !== get_current_screen()->base ) { + $error_message .= ' ' . sprintf( + /* translators: %s: Link to the plugins page. */ + __( 'Manage plugins.' ), + esc_url( admin_url( 'plugins.php' ) ) + ); + } + wp_admin_notice( - __( 'There are additional plugin dependencies that must be installed.' ), + $error_message, array( - 'type' => 'info', + 'type' => 'warning', ) ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index e598607acd..a3bfe6ef2f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-beta3-57768'; +$wp_version = '6.5-beta3-57769'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.