Skip to content

Commit

Permalink
split notices into separate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
afragen committed Oct 3, 2023
1 parent 04d2ffa commit 5f94ca7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/wp-admin/plugin-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
require_once ABSPATH . 'wp-admin/admin-header.php';

WP_Plugin_Dependencies::display_admin_notice_for_unmet_dependencies();
WP_Plugin_Dependencies::display_admin_notice_for_deactivated_dependents();
WP_Plugin_Dependencies::display_admin_notice_for_circular_dependencies();
?>
<div class="wrap <?php echo esc_attr( "plugin-install-tab-$tab" ); ?>">
<h1 class="wp-heading-inline">
Expand Down
3 changes: 2 additions & 1 deletion src/wp-admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,8 @@
?>

<?php WP_Plugin_Dependencies::display_admin_notice_for_unmet_dependencies(); ?>

<?php WP_Plugin_Dependencies::display_admin_notice_for_deactivated_dependents(); ?>
<?php WP_Plugin_Dependencies::display_admin_notice_for_circular_dependencies(); ?>
<div class="wrap">
<h1 class="wp-heading-inline">
<?php
Expand Down
39 changes: 23 additions & 16 deletions src/wp-includes/class-wp-plugin-dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,22 @@ public static function get_dependency_data( $slug ) {
* @since 6.5.0
*/
public static function display_admin_notice_for_unmet_dependencies() {
if ( in_array( false, self::get_dependency_filepaths(), true ) ) {
wp_admin_notice(
__( 'There are additional plugin dependencies that must be installed.' ),
array(
'type' => 'info',
)
);
}
}

/**
* Displays an admin notice if dependencies have been deactivated.
*
* @since 6.5.0
*/
public static function display_admin_notice_for_deactivated_dependents() {
/*
* Plugin deactivated if dependencies not met.
* Transient on a 10 second timeout.
Expand All @@ -362,24 +378,15 @@ public static function display_admin_notice_for_unmet_dependencies() {
'dismissible' => true,
)
);
} else {
// More dependencies to install.
$installed_slugs = array();
foreach ( array_keys( self::$plugins ) as $plugin ) {
$installed_slugs[] = self::convert_to_slug( $plugin );
}
$intersect = array_intersect( self::$dependency_slugs, $installed_slugs );
asort( $intersect );
if ( $intersect !== self::$dependency_slugs ) {
wp_admin_notice(
__( 'There are additional plugin dependencies that must be installed.' ),
array(
'type' => 'info',
)
);
}
}
}

/**
* Displays an admin notice if circular dependencies are installed.
*
* @since 6.5.0
*/
public static function display_admin_notice_for_circular_dependencies() {
$circular_dependencies = self::get_circular_dependencies();
if ( ! empty( $circular_dependencies ) && count( $circular_dependencies ) > 1 ) {
$circular_dependencies = array_unique( $circular_dependencies, SORT_REGULAR );
Expand Down

0 comments on commit 5f94ca7

Please sign in to comment.