Skip to content

Commit

Permalink
Introduces a function to get the min compat version.
Browse files Browse the repository at this point in the history
Introduces _get_plugin_wp_min_compatible_version().

By providing a global function, for-core plugins, such as Gutenberg,
can use it to check the minimum compatible version.

It provides a more foolproof way for the plugin to handle its response.
  • Loading branch information
hellofromtonya committed Feb 7, 2024
1 parent 4bef6a8 commit 7fe2161
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
24 changes: 24 additions & 0 deletions src/wp-includes/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,30 @@ function wp_not_installed() {
die();
}

/**
* Gets the for-core plugin's minimum compatible version.
*
* @since 6.5.0
* @access private
*
* @param string $plugin Plugin path relative to the plugins' directory.
* @return string Returns the minimum version on success, otherwise an empty string.
*/
function _get_plugin_wp_min_compatible_version( $plugin ) {
static $plugin_data = array(
'gutenberg/gutenberg.php' => array(
'name' => 'Gutenberg',
'minimum_compatible_version' => '17.7',
),
);

if ( ! isset( $plugin_data[ $plugin ] ) ) {
return '';
}

return $plugin_data[ $plugin ]['minimum_compatible_version'];
}

/**
* Retrieves an array of must-use plugin files.
*
Expand Down
30 changes: 3 additions & 27 deletions src/wp-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,29 +430,6 @@
*/
global $_found_incompatible_for_core_plugins, $_is_plugin_compatible_with_wp, $_handle_incompatible_for_core_plugins;

/**
* Gets the for-core plugin's minimum compatible version.
*
* @since 6.5.0
*
* @param string $plugin Plugin path relative to the plugins' directory.
* @return string Returns the minimum version if it's a for-core plugin, otherwise an empty string.
*/
function _get_for_core_plugin_min_wp_compat_version( $plugin ) {
static $plugin_data = array(
'gutenberg/gutenberg.php' => array(
'name' => 'Gutenberg',
'minimum_compatible_version' => '17.7',
),
);

if ( ! isset( $plugin_data[ $plugin ] ) ) {
return '';
}

return $plugin_data[ $plugin ]['minimum_compatible_version'];
}

// Found incompatible for-core plugins.
$_found_incompatible_for_core_plugins = array();

Expand All @@ -477,7 +454,8 @@ function _get_for_core_plugin_min_wp_compat_version( $plugin ) {
$plugin = substr( $plugin_absolute_path, $plugins_dir_strlen );

// Not a for-core plugin.
if ( ! isset( $_wp_for_core_plugins_compat_version[ $plugin ] ) ) {
$min_compat_version = _get_plugin_wp_min_compatible_version( $plugin );
if ( ! $min_compat_version ) {
return true;
}

Expand All @@ -502,8 +480,7 @@ function _get_for_core_plugin_min_wp_compat_version( $plugin ) {
return true;
}

// If compatible, bail out.
$min_compat_version = $_wp_for_core_plugins_compat_version[ $plugin ]['minimum_compatible_version'];
// Plugin is compatible.
if ( version_compare( $plugin_data['Version'], $min_compat_version, '>=' ) ) {
return true;
}
Expand Down Expand Up @@ -665,7 +642,6 @@ function _get_for_core_plugin_min_wp_compat_version( $plugin ) {
$plugin,
$_wp_plugin_file,
// Remove the for-core compatibility handler.
$_wp_for_core_plugins_compat_version,
$_wp_activated_plugins_to_compat_check,
$_is_plugin_compatible_with_wp,
$_handle_incompatible_for_core_plugins
Expand Down

0 comments on commit 7fe2161

Please sign in to comment.