Make WordPress Core

Changeset 57707

Timestamp:
02/25/2024 10:15:11 PM (5 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.

Location:
trunk
Files:
3 edited

Legend:

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

    r57610 r57707  
    87648764    list( $version ) = explode( '-', $wp_version );
    87658765
     8766
     8767
     8768
     8769
     8770
     8771
     8772
     8773
    87668774    return empty( $required ) || version_compare( $version, $required, '>=' );
    87678775}
  • trunk/tests/phpunit/tests/functions/isWpVersionCompatible.php

    r56971 r57707  
    4444        return array(
    4545            // Happy paths.
    46             'the same version'          => array(
     46            'the same version'          => array(
    4747                'required' => $wp_version,
    4848                'expected' => true,
    4949            ),
    50             'a lower required version'  => array(
    51                 'required' => $lower_version,
    52                 'expected' => true,
    53             ),
    54             'a higher required version' => array(
    55                 'required' => $higher_version,
    56                 'expected' => false,
     50            'a lower required version'        => array(
     51                'required' => $lower_version,
     52                'expected' => true,
     53            ),
     54            'a higher required version'       => array(
     55                'required' => $higher_version,
     56                'expected' => false,
     57            ),
     58
     59            // Acceptable versions containing '.0'.
     60            'correct version ending with x.0' => array(
     61                'required' => '5.0',
     62                'expected' => true,
     63            ),
     64            'correct version with x.0.x in middle of version' => array(
     65                'required' => '5.0.1',
     66                'expected' => true,
    5767            ),
    5868
    5969            // Falsey values.
    60             'false'                     => array(
     70            'false'                     => array(
    6171                'required' => false,
    6272                'expected' => true,
    6373            ),
    64             'null'                      => array(
     74            'null'                      => array(
    6575                'required' => null,
    6676                'expected' => true,
    6777            ),
    68             '0 int'                     => array(
     78            '0 int'                     => array(
    6979                'required' => 0,
    7080                'expected' => true,
    7181            ),
    72             '0.0 float'                 => array(
     82            '0.0 float'                 => array(
    7383                'required' => 0.0,
    7484                'expected' => true,
    7585            ),
    76             '0 string'                  => array(
     86            '0 string'                  => array(
    7787                'required' => '0',
    7888                'expected' => true,
    7989            ),
    80             'empty string'              => array(
     90            'empty string'              => array(
    8191                'required' => '',
    8292                'expected' => true,
    8393            ),
    84             'empty array'               => array(
     94            'empty array'               => array(
    8595                'required' => array(),
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
    86175                'expected' => true,
    87176            ),
  • trunk/tests/phpunit/tests/rest-api/rest-plugins-controller.php

    r57531 r57707  
    10221022        $this->assertSame( $network_only, $data['network_only'] );
    10231023        $this->assertSame( '5.6.0', $data['requires_php'] );
    1024         $this->assertSame( '5.4.0', $data['requires_wp'] );
     1024        $this->assertSame( '5.4', $data['requires_wp'] );
    10251025        $this->assertSame( 'test-plugin', $data['textdomain'] );
    10261026    }
     
    11501150 * Text Domain: test-plugin
    11511151 * Requires PHP: 5.6.0
    1152  * Requires at least: 5.4.0{$network}
     1152 * Requires at least: 5.4{$network}
    11531153 */
    11541154PHP;
Note: See TracChangeset for help on using the changeset viewer.