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
This commit is contained in:
Peter Wilson 2024-02-25 22:17:13 +00:00
parent 448030d355
commit 25ae4b9733
2 changed files with 9 additions and 1 deletions

View File

@ -8763,6 +8763,14 @@ function is_wp_version_compatible( $required ) {
// Strip off any -alpha, -RC, -beta, -src suffixes. // Strip off any -alpha, -RC, -beta, -src suffixes.
list( $version ) = explode( '-', $wp_version ); 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, '>=' ); return empty( $required ) || version_compare( $version, $required, '>=' );
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.