Plugins: Improve plugin dependency admin notices.

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
This commit is contained in:
desrosj 2024-03-05 06:27:09 +00:00
parent 9e0a116dbf
commit 20e57dca02
3 changed files with 44 additions and 8 deletions

View File

@ -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. */
__( '<strong>Requires:</strong> %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(
'<div class="requires"><p>%1$s</p><p>%2$s</p></div>',
$requires,
$dependency_note
$notice
);
}

View File

@ -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. */
__( '<a href="%s">Manage plugins</a>.' ),
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. */
__( '<a href="%s">Manage plugins</a>.' ),
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',
)
);
}

View File

@ -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.