WordPress.org

Make WordPress Core

Changeset 48666


Ignore:
Timestamp:
07/28/2020 04:05:39 PM (2 months ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Check WordPress and PHP version requirements when uploading a plugin or theme from ZIP file.

Props mariovalney, desrosj.
See #50593.

Location:
trunk/src/wp-admin/includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-plugin-upgrader.php

    r48446 r48666  
    442442        }
    443443
     444        $requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;
     445        $requires_wp  = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null;
     446
     447        if ( ! is_php_version_compatible( $requires_php ) ) {
     448            $error = sprintf(
     449                /* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
     450                __( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
     451                phpversion(),
     452                $requires_php
     453            );
     454
     455            return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error );
     456        }
     457
     458        if ( ! is_wp_version_compatible( $requires_wp ) ) {
     459            $error = sprintf(
     460                /* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
     461                __( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
     462                $GLOBALS['wp_version'],
     463                $requires_wp
     464            );
     465
     466            return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error );
     467        }
     468
    444469        return $source;
    445470    }
  • trunk/src/wp-admin/includes/class-theme-installer-skin.php

    r48661 r48666  
    222222        echo '<h2 class="update-from-upload-heading">' . esc_html( __( 'This theme is already installed.' ) ) . '</h2>';
    223223
    224         // Check errors for current theme
     224        // Check errors for current theme.
    225225        if ( is_wp_error( $current_theme_data->errors() ) ) {
    226226            $this->feedback( 'current_theme_has_errors', $current_theme_data->errors()->get_error_message() );
  • trunk/src/wp-admin/includes/class-theme-upgrader.php

    r48493 r48666  
    589589        }
    590590
     591        $requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;
     592        $requires_wp  = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null;
     593
     594        if ( ! is_php_version_compatible( $requires_php ) ) {
     595            $error = sprintf(
     596                /* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
     597                __( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
     598                phpversion(),
     599                $requires_php
     600            );
     601
     602            return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error );
     603        }
     604        if ( ! is_wp_version_compatible( $requires_wp ) ) {
     605            $error = sprintf(
     606                /* translators: 1: Current WordPress version, 2: Version required by the uploaded theme. */
     607                __( 'Your WordPress version is %1$s, however the uploaded theme requires %2$s.' ),
     608                $GLOBALS['wp_version'],
     609                $requires_wp
     610            );
     611
     612            return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error );
     613        }
     614
    591615        $this->new_theme_data = $info;
     616
    592617        return $source;
    593618    }
Note: See TracChangeset for help on using the changeset viewer.