From 25ae4b9733ebdd94ff2009b322812f03806a1dc3 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Sun, 25 Feb 2024 22:17:13 +0000 Subject: [PATCH] Upgrade/Install: Normalize major versions in `is_wp_version_compatible()`. Modify `is_wp_version_compatible()` to return the expected result for major WordPress versions formatted as either `x.x` or `x.x.0` (for example `6.5` and `6.5.0`). The WordPress project currently documents major version numbers in both formats leading to confusion for developers using the `is_wp_version_compatible()` function. As the PHP function `version_compare()` treats `x.x` and `x.x.0` as different version numbers this leads to unexpected results in the WP function. This change removes a trailing `.0` from major version numbers to account for the WordPress project using the two formats interchangeably. Props afragen, azaozz, costdev, joemcgill, jorbin, kkmuffme, sessioncookiemonster, swissspidy, wazeter. Fixes #59448. Built from https://develop.svn.wordpress.org/trunk@57707 git-svn-id: http://core.svn.wordpress.org/trunk@57208 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 8 ++++++++ wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index a3abfae9cf..fd305be20b 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -8763,6 +8763,14 @@ function is_wp_version_compatible( $required ) { // Strip off any -alpha, -RC, -beta, -src suffixes. list( $version ) = explode( '-', $wp_version ); + if ( is_string( $required ) ) { + $trimmed = trim( $required ); + + if ( substr_count( $trimmed, '.' ) > 1 && str_ends_with( $trimmed, '.0' ) ) { + $required = substr( $trimmed, 0, -2 ); + } + } + return empty( $required ) || version_compare( $version, $required, '>=' ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 9b78065426..496d6160b5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-beta2-57706'; +$wp_version = '6.5-beta2-57707'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.