Make WordPress Core


Ignore:
Timestamp:
03/05/2024 06:25:22 AM (13 months ago)
Author:
desrosj
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-plugins-list-table.php

    r57714 r57769  
    15681568        }
    15691569
    1570         $dependency_note = __( 'Note: This plugin cannot be activated until the plugins that are required by it are activated.' );
    1571 
    1572         $comma    = wp_get_list_item_separator();
    1573         $requires = sprintf(
     1570        $is_active = is_multisite() ? is_plugin_active_for_network( $dependent ) : is_plugin_active( $dependent );
     1571        $comma     = wp_get_list_item_separator();
     1572        $requires  = sprintf(
    15741573            /* translators: %s: List of dependency names. */
    15751574            __( '<strong>Requires:</strong> %s' ),
     
    15771576        );
    15781577
     1578        $notice        = '';
     1579        $error_message = '';
     1580        if ( WP_Plugin_Dependencies::has_unmet_dependencies( $dependent ) ) {
     1581            if ( $is_active ) {
     1582                $error_message = __( 'This plugin is active but may not function correctly because required plugins are missing or inactive.' );
     1583            } else {
     1584                $error_message = __( 'This plugin cannot be activated because required plugins are missing or inactive.' );
     1585            }
     1586            $notice = wp_get_admin_notice(
     1587                $error_message,
     1588                array(
     1589                    'type'               => 'error',
     1590                    'additional_classes' => array( 'inline', 'notice-alt' ),
     1591                )
     1592            );
     1593        }
     1594
    15791595        printf(
    15801596            '<div class="requires"><p>%1$s</p><p>%2$s</p></div>',
    15811597            $requires,
    1582             $dependency_note
     1598            $notice
    15831599        );
    15841600    }
Note: See TracChangeset for help on using the changeset viewer.