From 4171c2485c2c58dff7c8bc391e2dbe390a309872 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 13 Jul 2020 13:33:32 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@48455 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-plugin-installer-skin.php | 33 ++++++++++-------- .../includes/class-theme-installer-skin.php | 34 +++++++++---------- .../includes/class-theme-upgrader.php | 6 ++-- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/wp-admin/includes/class-plugin-installer-skin.php b/src/wp-admin/includes/class-plugin-installer-skin.php index 6a5cec123d..617d021168 100644 --- a/src/wp-admin/includes/class-plugin-installer-skin.php +++ b/src/wp-admin/includes/class-plugin-installer-skin.php @@ -186,7 +186,9 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin { $folder = ltrim( substr( $folder, strlen( WP_PLUGIN_DIR ) ), '/' ); $current_plugin_data = false; - foreach ( get_plugins() as $plugin => $plugin_data ) { + $all_plugins = get_plugins(); + + foreach ( $all_plugins as $plugin => $plugin_data ) { if ( strrpos( $plugin, $folder ) !== 0 ) { continue; } @@ -194,13 +196,15 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin { $current_plugin_data = $plugin_data; } - if ( empty( $current_plugin_data ) || empty( $this->upgrader->new_plugin_data ) ) { + $new_plugin_data = $this->upgrader->new_plugin_data; + + if ( ! $current_plugin_data || ! $new_plugin_data ) { return false; } echo '

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

'; - $this->is_downgrading = version_compare( $current_plugin_data['Version'], $this->upgrader->new_plugin_data['Version'], '>' ); + $this->is_downgrading = version_compare( $current_plugin_data['Version'], $new_plugin_data['Version'], '>' ); $rows = array( 'Name' => __( 'Plugin name' ), @@ -218,7 +222,7 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin { foreach ( $rows as $field => $label ) { $old_value = ! empty( $current_plugin_data[ $field ] ) ? (string) $current_plugin_data[ $field ] : '-'; - $new_value = ! empty( $this->upgrader->new_plugin_data[ $field ] ) ? (string) $this->upgrader->new_plugin_data[ $field ] : '-'; + $new_value = ! empty( $new_plugin_data[ $field ] ) ? (string) $new_plugin_data[ $field ] : '-'; $is_same_plugin = $is_same_plugin && ( $old_value === $new_value ); @@ -241,7 +245,7 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin { * @param array $current_plugin_data Array with current plugin data. * @param array $new_plugin_data Array with uploaded plugin data. */ - echo apply_filters( 'install_plugin_ovewrite_comparison', $table, $current_plugin_data, $this->upgrader->new_plugin_data ); + echo apply_filters( 'install_plugin_ovewrite_comparison', $table, $current_plugin_data, $new_plugin_data ); $install_actions = array(); $can_update = true; @@ -249,28 +253,27 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin { $blocked_message = '

' . esc_html( __( 'The plugin cannot be updated due to the following:' ) ) . '

'; $blocked_message .= '