WordPress.org

Make WordPress Core

Changeset 48455


Ignore:
Timestamp:
07/13/2020 01:33:32 PM (3 months ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Simplify compatibility checks for uploaded plugins and themes for better readability.

Use $new_plugin_data and $new_theme_data as a shorthand for the corresponding $this->upgrader properties.

Follow-up to [48390], [48448].

Props afragen.
See #9757.

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

Legend:

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

    r48453 r48455  
    187187
    188188        $current_plugin_data = false;
    189         foreach ( get_plugins() as $plugin => $plugin_data ) {
     189        $all_plugins         = get_plugins();
     190
     191        foreach ( $all_plugins as $plugin => $plugin_data ) {
    190192            if ( strrpos( $plugin, $folder ) !== 0 ) {
    191193                continue;
     
    195197        }
    196198
    197         if ( empty( $current_plugin_data ) || empty( $this->upgrader->new_plugin_data ) ) {
     199        $new_plugin_data = $this->upgrader->new_plugin_data;
     200
     201        if ( ! $current_plugin_data || ! $new_plugin_data ) {
    198202            return false;
    199203        }
     
    201205        echo '<h2 class="update-from-upload-heading">' . esc_html( __( 'This plugin is already installed.' ) ) . '</h2>';
    202206
    203         $this->is_downgrading = version_compare( $current_plugin_data['Version'], $this->upgrader->new_plugin_data['Version'], '>' );
     207        $this->is_downgrading = version_compare( $current_plugin_data['Version'], $new_plugin_data['Version'], '>' );
    204208
    205209        $rows = array(
     
    219223        foreach ( $rows as $field => $label ) {
    220224            $old_value = ! empty( $current_plugin_data[ $field ] ) ? (string) $current_plugin_data[ $field ] : '-';
    221             $new_value = ! empty( $this->upgrader->new_plugin_data[ $field ] ) ? (string) $this->upgrader->new_plugin_data[ $field ] : '-';
     225            $new_value = ! empty( $new_plugin_data[ $field ] ) ? (string) $new_plugin_data[ $field ] : '-';
    222226
    223227            $is_same_plugin = $is_same_plugin && ( $old_value === $new_value );
     
    242246         * @param array  $new_plugin_data     Array with uploaded plugin data.
    243247         */
    244         echo apply_filters( 'install_plugin_ovewrite_comparison', $table, $current_plugin_data, $this->upgrader->new_plugin_data );
     248        echo apply_filters( 'install_plugin_ovewrite_comparison', $table, $current_plugin_data, $new_plugin_data );
    245249
    246250        $install_actions = array();
     
    250254        $blocked_message .= '<ul class="ul-disc">';
    251255
    252         if ( ! empty( $this->upgrader->new_plugin_data['RequiresPHP'] )
    253             && ! is_php_version_compatible( $this->upgrader->new_plugin_data['RequiresPHP'] )
    254         ) {
     256        $requires_php = isset( $new_plugin_data['RequiresPHP'] ) ? $new_plugin_data['RequiresPHP'] : null;
     257        $requires_wp  = isset( $new_plugin_data['RequiresWP'] ) ? $new_plugin_data['RequiresWP'] : null;
     258
     259        if ( ! is_php_version_compatible( $requires_php ) ) {
    255260            $error = sprintf(
    256261                /* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
    257262                __( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
    258263                phpversion(),
    259                 $this->upgrader->new_plugin_data['RequiresPHP']
     264                $requires_php
    260265            );
    261266
     
    264269        }
    265270
    266         if ( ! empty( $this->upgrader->new_plugin_data['RequiresWP'] )
    267             && ! is_wp_version_compatible( $this->upgrader->new_plugin_data['RequiresWP'] )
    268         ) {
     271        if ( ! is_wp_version_compatible( $requires_wp ) ) {
    269272            $error = sprintf(
    270273                /* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
    271274                __( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
    272                 $GLOBALS['wp_version'],
    273                 $this->upgrader->new_plugin_data['RequiresWP']
     275                get_bloginfo( 'version' ),
     276                $requires_wp
    274277            );
    275278
     
    325328         * @param array    $new_plugin_data Array with uploaded plugin data.
    326329         */
    327         $install_actions = apply_filters( 'install_plugin_ovewrite_actions', $install_actions, $this->api, $this->upgrader->new_plugin_data );
     330        $install_actions = apply_filters( 'install_plugin_ovewrite_actions', $install_actions, $this->api, $new_plugin_data );
    328331
    329332        if ( ! empty( $install_actions ) ) {
  • trunk/src/wp-admin/includes/class-theme-installer-skin.php

    r48453 r48455  
    208208        }
    209209
    210         if ( empty( $current_theme_data ) || empty( $this->upgrader->new_theme_data ) ) {
     210        $new_theme_data = $this->upgrader->new_theme_data;
     211
     212        if ( ! $current_theme_data || ! $new_theme_data ) {
    211213            return false;
    212214        }
     
    219221        }
    220222
    221         $this->is_downgrading = version_compare( $current_theme_data['Version'], $this->upgrader->new_theme_data['Version'], '>' );
     223        $this->is_downgrading = version_compare( $current_theme_data['Version'], $new_theme_data['Version'], '>' );
    222224
    223225        $is_invalid_parent = false;
    224         if ( ! empty( $this->upgrader->new_theme_data['Template'] ) ) {
    225             $is_invalid_parent = ! in_array( $this->upgrader->new_theme_data['Template'], array_keys( $all_themes ), true );
     226        if ( ! empty( $new_theme_data['Template'] ) ) {
     227            $is_invalid_parent = ! in_array( $new_theme_data['Template'], array_keys( $all_themes ), true );
    226228        }
    227229
     
    244246            $old_value = $old_value ? (string) $old_value : '-';
    245247
    246             $new_value = ! empty( $this->upgrader->new_theme_data[ $field ] ) ? (string) $this->upgrader->new_theme_data[ $field ] : '-';
     248            $new_value = ! empty( $new_theme_data[ $field ] ) ? (string) $new_theme_data[ $field ] : '-';
    247249
    248250            if ( $old_value === $new_value && '-' === $new_value && 'Template' === $field ) {
     
    277279         * @param array  $new_theme_data     Array with uploaded theme data.
    278280         */
    279         echo apply_filters( 'install_theme_overwrite_comparison', $table, $current_theme_data, $this->upgrader->new_theme_data );
     281        echo apply_filters( 'install_theme_overwrite_comparison', $table, $current_theme_data, $new_theme_data );
    280282
    281283        $install_actions = array();
     
    285287        $blocked_message .= '<ul class="ul-disc">';
    286288
    287         if ( ! empty( $this->upgrader->new_theme_data['RequiresPHP'] )
    288             && ! is_php_version_compatible( $this->upgrader->new_theme_data['RequiresPHP'] )
    289         ) {
     289        $requires_php = isset( $new_theme_data['RequiresPHP'] ) ? $new_theme_data['RequiresPHP'] : null;
     290        $requires_wp  = isset( $new_theme_data['RequiresWP'] ) ? $new_theme_data['RequiresWP'] : null;
     291
     292        if ( ! is_php_version_compatible( $requires_php ) ) {
    290293            $error = sprintf(
    291294                /* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
    292295                __( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
    293296                phpversion(),
    294                 $this->upgrader->new_theme_data['RequiresPHP']
     297                $requires_php
    295298            );
    296299
     
    299302        }
    300303
    301         if ( ! empty( $this->upgrader->new_theme_data['RequiresWP'] )
    302             && ! is_wp_version_compatible( $this->upgrader->new_theme_data['RequiresWP'] )
    303         ) {
     304        if ( ! is_wp_version_compatible( $requires_wp ) ) {
    304305            $error = sprintf(
    305306                /* translators: 1: Current WordPress version, 2: Version required by the uploaded theme. */
    306307                __( 'Your WordPress version is %1$s, however the uploaded theme requires %2$s.' ),
    307                 $GLOBALS['wp_version'],
    308                 $this->upgrader->new_theme_data['RequiresWP']
     308                get_bloginfo( 'version' ),
     309                $requires_wp
    309310            );
    310311
     
    360361         * @param array    $new_theme_data  Array with uploaded theme data.
    361362         */
    362         $install_actions = apply_filters( 'install_theme_ovewrite_actions', $install_actions, $this->api, $this->upgrader->new_theme_data );
     363        $install_actions = apply_filters( 'install_theme_ovewrite_actions', $install_actions, $this->api, $new_theme_data );
    363364
    364365        if ( ! empty( $install_actions ) ) {
     
    372373        return true;
    373374    }
    374 
    375375}
  • trunk/src/wp-admin/includes/class-theme-upgrader.php

    r48446 r48455  
    274274             * @since 5.5.0
    275275             *
    276              * @param string  $package          The package file.
    277              * @param array   $new_plugin_data The new theme data.
    278              * @param string  $package_type     The package type (plugin or theme).
     276             * @param string  $package        The package file.
     277             * @param array   $new_theme_data The new theme data.
     278             * @param string  $package_type   The package type (plugin or theme).
    279279             */
    280280            do_action( 'upgrader_overwrote_package', $package, $this->new_theme_data, 'theme' );
Note: See TracChangeset for help on using the changeset viewer.