From 4cfc383544f0e762cfb4d45cb9001ed8a77bd83b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 28 Jul 2020 16:07:02 +0000 Subject: [PATCH] Upgrade/Install: Check WordPress and PHP version requirements when uploading a plugin or theme from ZIP file. Props mariovalney, desrosj. See #50593. Built from https://develop.svn.wordpress.org/trunk@48666 git-svn-id: http://core.svn.wordpress.org/trunk@48428 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-plugin-upgrader.php | 25 +++++++++++++++++++ .../includes/class-theme-installer-skin.php | 2 +- wp-admin/includes/class-theme-upgrader.php | 25 +++++++++++++++++++ wp-includes/version.php | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/wp-admin/includes/class-plugin-upgrader.php b/wp-admin/includes/class-plugin-upgrader.php index c5476c886b..53c7da1ced 100644 --- a/wp-admin/includes/class-plugin-upgrader.php +++ b/wp-admin/includes/class-plugin-upgrader.php @@ -441,6 +441,31 @@ class Plugin_Upgrader extends WP_Upgrader { return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) ); } + $requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null; + $requires_wp = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null; + + if ( ! is_php_version_compatible( $requires_php ) ) { + $error = sprintf( + /* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */ + __( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ), + phpversion(), + $requires_php + ); + + return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error ); + } + + if ( ! is_wp_version_compatible( $requires_wp ) ) { + $error = sprintf( + /* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */ + __( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ), + $GLOBALS['wp_version'], + $requires_wp + ); + + return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error ); + } + return $source; } diff --git a/wp-admin/includes/class-theme-installer-skin.php b/wp-admin/includes/class-theme-installer-skin.php index 76d2030f6d..cd6145a978 100644 --- a/wp-admin/includes/class-theme-installer-skin.php +++ b/wp-admin/includes/class-theme-installer-skin.php @@ -221,7 +221,7 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin { echo '

' . esc_html( __( 'This theme is already installed.' ) ) . '

'; - // Check errors for current theme + // Check errors for current theme. if ( is_wp_error( $current_theme_data->errors() ) ) { $this->feedback( 'current_theme_has_errors', $current_theme_data->errors()->get_error_message() ); } diff --git a/wp-admin/includes/class-theme-upgrader.php b/wp-admin/includes/class-theme-upgrader.php index 4ff5109e63..a5901b9fc7 100644 --- a/wp-admin/includes/class-theme-upgrader.php +++ b/wp-admin/includes/class-theme-upgrader.php @@ -588,7 +588,32 @@ class Theme_Upgrader extends WP_Upgrader { ); } + $requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null; + $requires_wp = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null; + + if ( ! is_php_version_compatible( $requires_php ) ) { + $error = sprintf( + /* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */ + __( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ), + phpversion(), + $requires_php + ); + + return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error ); + } + if ( ! is_wp_version_compatible( $requires_wp ) ) { + $error = sprintf( + /* translators: 1: Current WordPress version, 2: Version required by the uploaded theme. */ + __( 'Your WordPress version is %1$s, however the uploaded theme requires %2$s.' ), + $GLOBALS['wp_version'], + $requires_wp + ); + + return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error ); + } + $this->new_theme_data = $info; + return $source; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 3b0a51fecd..5d66aab86f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-beta4-48665'; +$wp_version = '5.5-beta4-48666'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.