Make WordPress Core

Changeset 45185


Ignore:
Timestamp:
04/12/2019 11:55:19 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Plugins: Introduce is_wp_version_compatible() and is_php_version_compatible() for checking compatibility with the current WordPress or PHP version.

Props afragen.
Fixes #46599.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-plugin-install-list-table.php

    r45043 r45185  
    503503            }
    504504
    505             $wp_version = get_bloginfo( 'version' );
    506 
    507             $compatible_php = ( empty( $plugin['requires_php'] ) || version_compare( phpversion(), $plugin['requires_php'], '>=' ) );
    508             $tested_wp      = ( empty( $plugin['tested'] ) || version_compare( $wp_version, $plugin['tested'], '<=' ) );
    509             $compatible_wp  = ( empty( $plugin['requires'] ) || version_compare( $wp_version, $plugin['requires'], '>=' ) );
     505            $requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
     506            $requires_wp  = isset( $plugin['requires'] ) ? $plugin['requires'] : null;
     507
     508            $compatible_php = is_php_version_compatible( $requires_php );
     509            $compatible_wp  = is_wp_version_compatible( $requires_wp );
     510            $tested_wp      = ( empty( $plugin['tested'] ) || version_compare( get_bloginfo( 'version' ), $plugin['tested'], '<=' ) );
    510511
    511512            $action_links = array();
  • trunk/src/wp-admin/includes/class-wp-plugins-list-table.php

    r45021 r45185  
    762762        }
    763763
    764         $compatible_php = ( empty( $plugin_data['requires_php'] ) || version_compare( phpversion(), $plugin_data['requires_php'], '>=' ) );
     764        $requires_php   = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
     765        $compatible_php = is_php_version_compatible( $requires_php );
    765766        $class          = $is_active ? 'active' : 'inactive';
    766767        $checkbox_id    = 'checkbox_' . md5( $plugin_data['Name'] );
  • trunk/src/wp-admin/includes/plugin-install.php

    r44937 r45185  
    755755    <div id="section-holder" class="wrap">
    756756    <?php
    757     $wp_version = get_bloginfo( 'version' );
    758 
    759     $compatible_php = ( empty( $api->requires_php ) || version_compare( phpversion(), $api->requires_php, '>=' ) );
    760     $tested_wp      = ( empty( $api->tested ) || version_compare( $wp_version, $api->tested, '<=' ) );
    761     $compatible_wp  = ( empty( $api->requires ) || version_compare( $wp_version, $api->requires, '>=' ) );
     757    $requires_php = isset( $api->requires_php ) ? $api->requires_php : null;
     758    $requires_wp  = isset( $api->requires ) ? $api->requires : null;
     759
     760    $compatible_php = is_php_version_compatible( $requires_php );
     761    $compatible_wp  = is_wp_version_compatible( $requires_wp );
     762    $tested_wp      = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) );
    762763
    763764    if ( ! $compatible_php ) {
  • trunk/src/wp-admin/includes/plugin.php

    r45116 r45185  
    11001100    }
    11011101
    1102     $plugin_data['wp_compatible']  = version_compare( get_bloginfo( 'version' ), $plugin_data['requires'], '>=' );
    1103     $plugin_data['php_compatible'] = version_compare( phpversion(), $plugin_data['requires_php'], '>=' );
     1102    $plugin_data['wp_compatible']  = is_wp_version_compatible( $plugin_data['requires'] );
     1103    $plugin_data['php_compatible'] = is_php_version_compatible( $plugin_data['requires_php'] );
    11041104
    11051105    $plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) );
  • trunk/src/wp-admin/includes/update.php

    r45117 r45185  
    401401        }
    402402
    403         $compatible_php = ( empty( $response->requires_php ) || version_compare( phpversion(), $response->requires_php, '>=' ) );
     403        $requires_php   = isset( $response->requires_php ) ? $response->requires_php : null;
     404        $compatible_php = is_php_version_compatible( $requires_php );
    404405        $notice_type    = $compatible_php ? 'notice-warning' : 'notice-error';
    405406
  • trunk/src/wp-admin/update-core.php

    r45184 r45185  
    296296        }
    297297
    298         $compatible_php = ( empty( $plugin_data->update->requires_php ) || version_compare( phpversion(), $plugin_data->update->requires_php, '>=' ) );
     298        $requires_php   = isset( $plugin_data->update->requires_php ) ? $plugin_data->update->requires_php : null;
     299        $compatible_php = is_php_version_compatible( $requires_php );
    299300
    300301        if ( ! $compatible_php && current_user_can( 'update_php' ) ) {
  • trunk/src/wp-includes/functions.php

    r45177 r45185  
    34183418    <data>
    34193419        <status>{$r['response']}</status>
    3420     </data> 
     3420    </data>
    34213421</error>
    34223422
     
    71227122    return $size;
    71237123}
     7124
     7125/**
     7126* Checks compatibility with the current WordPress version.
     7127*
     7128* @since 5.2.0
     7129*
     7130* @param string $required Minimum required WordPress version.
     7131* @return bool True if required version is compatible or empty, false if not.
     7132*/
     7133function is_wp_version_compatible( $required ) {
     7134    return empty( $required ) || version_compare( get_bloginfo( 'version' ), $required, '>=' );
     7135}
     7136
     7137/**
     7138 * Checks compatibility with the current PHP version.
     7139 *
     7140 * @since 5.2.0
     7141 *
     7142 * @param string $required Minimum required PHP version.
     7143 * @return bool True if required version is compatible or empty, false if not.
     7144 */
     7145function is_php_version_compatible( $required ) {
     7146    return empty( $required ) || version_compare( phpversion(), $required, '>=' );
     7147}
Note: See TracChangeset for help on using the changeset viewer.