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. git-svn-id: https://develop.svn.wordpress.org/trunk@45185 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e844945b31
commit
78e868e4c7
@ -502,11 +502,12 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
|
|||||||
$author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '</cite>';
|
$author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '</cite>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$wp_version = get_bloginfo( 'version' );
|
$requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
|
||||||
|
$requires_wp = isset( $plugin['requires'] ) ? $plugin['requires'] : null;
|
||||||
|
|
||||||
$compatible_php = ( empty( $plugin['requires_php'] ) || version_compare( phpversion(), $plugin['requires_php'], '>=' ) );
|
$compatible_php = is_php_version_compatible( $requires_php );
|
||||||
$tested_wp = ( empty( $plugin['tested'] ) || version_compare( $wp_version, $plugin['tested'], '<=' ) );
|
$compatible_wp = is_wp_version_compatible( $requires_wp );
|
||||||
$compatible_wp = ( empty( $plugin['requires'] ) || version_compare( $wp_version, $plugin['requires'], '>=' ) );
|
$tested_wp = ( empty( $plugin['tested'] ) || version_compare( get_bloginfo( 'version' ), $plugin['tested'], '<=' ) );
|
||||||
|
|
||||||
$action_links = array();
|
$action_links = array();
|
||||||
|
|
||||||
|
@ -761,7 +761,8 @@ class WP_Plugins_List_Table extends WP_List_Table {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$compatible_php = ( empty( $plugin_data['requires_php'] ) || version_compare( phpversion(), $plugin_data['requires_php'], '>=' ) );
|
$requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
|
||||||
|
$compatible_php = is_php_version_compatible( $requires_php );
|
||||||
$class = $is_active ? 'active' : 'inactive';
|
$class = $is_active ? 'active' : 'inactive';
|
||||||
$checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] );
|
$checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] );
|
||||||
if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) || ! $compatible_php ) {
|
if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) || ! $compatible_php ) {
|
||||||
|
@ -754,11 +754,12 @@ function install_plugin_information() {
|
|||||||
</div>
|
</div>
|
||||||
<div id="section-holder" class="wrap">
|
<div id="section-holder" class="wrap">
|
||||||
<?php
|
<?php
|
||||||
$wp_version = get_bloginfo( 'version' );
|
$requires_php = isset( $api->requires_php ) ? $api->requires_php : null;
|
||||||
|
$requires_wp = isset( $api->requires ) ? $api->requires : null;
|
||||||
|
|
||||||
$compatible_php = ( empty( $api->requires_php ) || version_compare( phpversion(), $api->requires_php, '>=' ) );
|
$compatible_php = is_php_version_compatible( $requires_php );
|
||||||
$tested_wp = ( empty( $api->tested ) || version_compare( $wp_version, $api->tested, '<=' ) );
|
$compatible_wp = is_wp_version_compatible( $requires_wp );
|
||||||
$compatible_wp = ( empty( $api->requires ) || version_compare( $wp_version, $api->requires, '>=' ) );
|
$tested_wp = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) );
|
||||||
|
|
||||||
if ( ! $compatible_php ) {
|
if ( ! $compatible_php ) {
|
||||||
echo '<div class="notice notice-error notice-alt"><p>';
|
echo '<div class="notice notice-error notice-alt"><p>';
|
||||||
|
@ -1099,8 +1099,8 @@ function validate_plugin_requirements( $plugin ) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$plugin_data['wp_compatible'] = version_compare( get_bloginfo( 'version' ), $plugin_data['requires'], '>=' );
|
$plugin_data['wp_compatible'] = is_wp_version_compatible( $plugin_data['requires'] );
|
||||||
$plugin_data['php_compatible'] = version_compare( phpversion(), $plugin_data['requires_php'], '>=' );
|
$plugin_data['php_compatible'] = is_php_version_compatible( $plugin_data['requires_php'] );
|
||||||
|
|
||||||
$plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) );
|
$plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) );
|
||||||
|
|
||||||
|
@ -400,7 +400,8 @@ function wp_plugin_update_row( $file, $plugin_data ) {
|
|||||||
$active_class = is_plugin_active( $file ) ? ' active' : '';
|
$active_class = is_plugin_active( $file ) ? ' active' : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$compatible_php = ( empty( $response->requires_php ) || version_compare( phpversion(), $response->requires_php, '>=' ) );
|
$requires_php = isset( $response->requires_php ) ? $response->requires_php : null;
|
||||||
|
$compatible_php = is_php_version_compatible( $requires_php );
|
||||||
$notice_type = $compatible_php ? 'notice-warning' : 'notice-error';
|
$notice_type = $compatible_php ? 'notice-warning' : 'notice-error';
|
||||||
|
|
||||||
echo '<tr class="plugin-update-tr' . $active_class . '" id="' . esc_attr( $response->slug . '-update' ) . '" data-slug="' . esc_attr( $response->slug ) . '" data-plugin="' . esc_attr( $file ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice inline ' . $notice_type . ' notice-alt"><p>';
|
echo '<tr class="plugin-update-tr' . $active_class . '" id="' . esc_attr( $response->slug . '-update' ) . '" data-slug="' . esc_attr( $response->slug ) . '" data-plugin="' . esc_attr( $file ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice inline ' . $notice_type . ' notice-alt"><p>';
|
||||||
|
@ -295,7 +295,8 @@ function list_plugin_updates() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$compatible_php = ( empty( $plugin_data->update->requires_php ) || version_compare( phpversion(), $plugin_data->update->requires_php, '>=' ) );
|
$requires_php = isset( $plugin_data->update->requires_php ) ? $plugin_data->update->requires_php : null;
|
||||||
|
$compatible_php = is_php_version_compatible( $requires_php );
|
||||||
|
|
||||||
if ( ! $compatible_php && current_user_can( 'update_php' ) ) {
|
if ( ! $compatible_php && current_user_can( 'update_php' ) ) {
|
||||||
$compat .= '<br>' . __( 'This update doesn’t work with your version of PHP.' ) . ' ';
|
$compat .= '<br>' . __( 'This update doesn’t work with your version of PHP.' ) . ' ';
|
||||||
|
@ -7121,3 +7121,27 @@ function recurse_dirsize( $directory, $exclude = null, $max_execution_time = nul
|
|||||||
}
|
}
|
||||||
return $size;
|
return $size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks compatibility with the current WordPress version.
|
||||||
|
*
|
||||||
|
* @since 5.2.0
|
||||||
|
*
|
||||||
|
* @param string $required Minimum required WordPress version.
|
||||||
|
* @return bool True if required version is compatible or empty, false if not.
|
||||||
|
*/
|
||||||
|
function is_wp_version_compatible( $required ) {
|
||||||
|
return empty( $required ) || version_compare( get_bloginfo( 'version' ), $required, '>=' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks compatibility with the current PHP version.
|
||||||
|
*
|
||||||
|
* @since 5.2.0
|
||||||
|
*
|
||||||
|
* @param string $required Minimum required PHP version.
|
||||||
|
* @return bool True if required version is compatible or empty, false if not.
|
||||||
|
*/
|
||||||
|
function is_php_version_compatible( $required ) {
|
||||||
|
return empty( $required ) || version_compare( phpversion(), $required, '>=' );
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user