Make WordPress Core


Ignore:
Timestamp:
02/25/2024 10:15:11 PM (7 months ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r57610 r57707  
    87648764    list( $version ) = explode( '-', $wp_version );
    87658765
     8766    if ( is_string( $required ) ) {
     8767        $trimmed = trim( $required );
     8768
     8769        if ( substr_count( $trimmed, '.' ) > 1 && str_ends_with( $trimmed, '.0' ) ) {
     8770            $required = substr( $trimmed, 0, -2 );
     8771        }
     8772    }
     8773
    87668774    return empty( $required ) || version_compare( $version, $required, '>=' );
    87678775}
Note: See TracChangeset for help on using the changeset viewer.