Ticket #9757: 9757.3.patch
File 9757.3.patch, 29.7 KB (added by , 5 years ago) |
---|
-
src/wp-admin/css/themes.css
1030 1030 overflow: hidden; 1031 1031 position: relative; 1032 1032 top: 10px; 1033 text-align: center; 1033 1034 } 1034 1035 1035 .upload-plugin-wrap {1036 display: none;1037 }1038 1039 1036 .show-upload-view .upload-theme, 1040 1037 .show-upload-view .upload-plugin, 1041 1038 .show-upload-view .upload-plugin-wrap, … … 1049 1046 border: 1px solid #ccd0d4; 1050 1047 padding: 30px; 1051 1048 margin: 30px auto; 1052 max-width: 380px; 1053 display: flex; 1049 display: inline-flex; 1054 1050 justify-content: space-between; 1055 1051 align-items: center; 1056 1052 } 1057 1053 1054 .upload-theme .wp-upload-form input[type="file"], 1055 .upload-plugin .wp-upload-form input[type="file"] { 1056 margin-right: 10px; 1057 } 1058 1058 1059 .upload-theme .install-help, 1059 1060 .upload-plugin .install-help { 1060 1061 color: #555d66; /* #f1f1f1 background */ … … 1093 1094 .upload-theme .install-help { 1094 1095 font-size: 15px; 1095 1096 padding: 20px 0 0; 1096 text-align: left;1097 1097 } 1098 1098 } 1099 1099 … … 1116 1116 line-height: 1.9; 1117 1117 } 1118 1118 1119 .compare-themes-table, 1120 .compare-plugins-table { 1121 text-align: left; 1122 margin: 1em 0 2em; 1123 border-collapse: collapse; 1124 } 1125 1126 .compare-themes-table th, 1127 .compare-plugins-table th { 1128 font-weight: bold; 1129 padding: 3px 10px; 1130 } 1131 1132 .compare-themes-table td, 1133 .compare-plugins-table td { 1134 padding: 3px 10px; 1135 } 1136 1137 .compare-themes-table tr.warning, 1138 .compare-plugins-table tr.warning, 1139 a.ovewrite-uploaded-theme { 1140 color: #a00; 1141 } 1142 1143 a.ovewrite-uploaded-plugin { 1144 color: #a00; 1145 margin-left: 10px; 1146 } 1147 1148 1149 a.ovewrite-uploaded-theme:hover, 1150 a.ovewrite-uploaded-plugin:hover { 1151 color: #d80707; 1152 } 1153 1119 1154 /*------------------------------------------------------------------------------ 1120 1155 16.3 - Custom Header Screen 1121 1156 ------------------------------------------------------------------------------*/ -
src/wp-admin/includes/class-plugin-installer-skin.php
18 18 class Plugin_Installer_Skin extends WP_Upgrader_Skin { 19 19 public $api; 20 20 public $type; 21 public $url; 22 public $overwrite; 21 23 24 private $is_downgrading = false; 25 22 26 /** 23 27 * @param array $args 24 28 */ 25 29 public function __construct( $args = array() ) { 26 30 $defaults = array( 27 'type' => 'web', 28 'url' => '', 29 'plugin' => '', 30 'nonce' => '', 31 'title' => '', 31 'type' => 'web', 32 'url' => '', 33 'plugin' => '', 34 'nonce' => '', 35 'title' => '', 36 'overwrite' => '', 32 37 ); 33 38 $args = wp_parse_args( $args, $defaults ); 34 39 35 $this->type = $args['type']; 36 $this->api = isset( $args['api'] ) ? $args['api'] : array(); 40 $this->type = $args['type']; 41 $this->url = $args['url']; 42 $this->api = isset( $args['api'] ) ? $args['api'] : array(); 43 $this->overwrite = $args['overwrite']; 37 44 38 45 parent::__construct( $args ); 39 46 } … … 43 50 public function before() { 44 51 if ( ! empty( $this->api ) ) { 45 52 $this->upgrader->strings['process_success'] = sprintf( 46 /* translators: 1: Plugin name, 2: Plugin version. */ 47 __( 'Successfully installed the plugin <strong>%1$s %2$s</strong>.' ), 53 $this->upgrader->strings['process_success_specific'], 48 54 $this->api->name, 49 55 $this->api->version 50 56 ); … … 54 60 /** 55 61 */ 56 62 public function after() { 63 $compare_table = $this->compare_table(); 64 65 if ( $compare_table ) { 66 $this->feedback( 'compare_before_overwrite' ); 67 echo $compare_table; 68 69 $overwrite = 'update-plugin'; 70 $label = __( 'Remove current and install the uploaded version' ); 71 72 if ( $this->is_downgrading ) { 73 $overwrite = 'downgrade-plugin'; 74 75 if ( isset( $this->upgrader->new_plugin_data['Version'] ) ) { 76 $label = sprintf( __( 'Remove current and install version %s' ), $this->upgrader->new_plugin_data['Version'] ); 77 } 78 } 79 80 $install_actions = array( 81 'plugins_page' => sprintf( 82 '<a href="%s">%s</a>', 83 self_admin_url( 'plugin-install.php' ), 84 __( 'Cancel and go back' ) 85 ), 86 'ovewrite_plugin' => sprintf( 87 '<a class="ovewrite-uploaded-plugin" href="%s" target="_parent">%s</a>', 88 wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'plugin-upload' ), 89 $label 90 ), 91 ); 92 93 $backup_warning = __( '<strong>Important:</strong> Before updating, please <a href="https://wordpress.org/support/article/wordpress-backups/">back up your database and files</a>.' ); 94 $this->feedback( '<div class="notice notice-warning inline"><p>' . $backup_warning . '</p></div>' ); 95 96 /** 97 * Filters the list of action links available following a single plugin installation failed but ovewrite is allowed. 98 * 99 * @since 5.5.0 100 * 101 * @param string[] $install_actions Array of plugin action links. 102 * @param object $api Object containing WordPress.org API plugin data. 103 * @param array $new_plugin_data Array with uploaded plugin data. 104 */ 105 $install_actions = apply_filters( 'install_plugin_ovewrite_actions', $install_actions, $this->api, $this->upgrader->new_plugin_data ); 106 107 if ( ! empty( $install_actions ) ) { 108 $this->feedback( implode( ' ', (array) $install_actions ) ); 109 } 110 111 return; 112 } 113 57 114 $plugin_file = $this->upgrader->plugin_info(); 58 115 59 116 $install_actions = array(); … … 117 174 118 175 if ( ! $this->result || is_wp_error( $this->result ) ) { 119 176 unset( $install_actions['activate_plugin'], $install_actions['network_activate'] ); 120 } elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) ) {177 } elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) || is_plugin_active( $plugin_file ) ) { 121 178 unset( $install_actions['activate_plugin'] ); 122 179 } 123 180 … … 138 195 $this->feedback( implode( ' ', (array) $install_actions ) ); 139 196 } 140 197 } 198 199 /** 200 * Create the compare table to show user information about overwrite plugin on upload. 201 * 202 * @since 5.5.0 203 * 204 * @return string $table The table output. 205 */ 206 private function compare_table() { 207 if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) { 208 return ''; 209 } 210 211 $folder = $this->result->get_error_data( 'folder_exists' ); 212 $folder = ltrim( substr( $folder, strlen( WP_PLUGIN_DIR ) ), '/' ); 213 214 $current_plugin_data = false; 215 foreach ( get_plugins() as $plugin => $plugin_data ) { 216 if ( strrpos( $plugin, $folder ) !== 0 ) { 217 continue; 218 } 219 220 $current_plugin_data = $plugin_data; 221 } 222 223 if ( empty( $current_plugin_data ) || empty( $this->upgrader->new_plugin_data ) ) { 224 return ''; 225 } 226 227 $this->is_downgrading = version_compare( $current_plugin_data['Version'], $this->upgrader->new_plugin_data['Version'], '>' ); 228 229 $rows = array( 230 'Name' => __( 'Plugin Name' ), 231 'Version' => __( 'Version' ), 232 'Author' => __( 'Author' ), 233 'RequiresWP' => __( 'Requires at least' ), 234 'RequiresPHP' => __( 'Requires PHP' ), 235 ); 236 237 $table = '<table class="compare-plugins-table"><tbody>'; 238 $table .= '<tr><th></th><th>' . esc_html( __( 'Current' ) ) . '</th><th>' . esc_html( __( 'Uploaded' ) ) . '</th></tr>'; 239 240 $is_same_plugin = true; // Let's consider only these rows 241 foreach ( $rows as $field => $label ) { 242 $old_value = ! empty( $current_plugin_data[ $field ] ) ? $current_plugin_data[ $field ] : '-'; 243 $new_value = ! empty( $this->upgrader->new_plugin_data[ $field ] ) ? $this->upgrader->new_plugin_data[ $field ] : '-'; 244 245 $is_same_plugin = $is_same_plugin && ( $old_value === $new_value ); 246 247 $diff_field = ( 'Version' !== $field && $new_value !== $old_value ); 248 $diff_version = ( 'Version' === $field && $this->is_downgrading ); 249 250 $table .= ( $diff_field || $diff_version ) ? '<tr class="warning">' : '<tr>'; 251 $table .= '<td>' . $label . '</td><td>' . esc_html( $old_value ) . '</td><td>' . esc_html( $new_value ) . '</td></tr>'; 252 } 253 254 $table .= '</tbody></table>'; 255 256 if ( $is_same_plugin ) { 257 $this->feedback( 'reuploading_plugin' ); 258 } 259 260 /** 261 * Filters the compare table output for overwrite a plugin package on upload. 262 * 263 * @since 5.5.0 264 * 265 * @param string $table The output table with Name, Version, Author, RequiresWP and RequiresPHP info. 266 * @param array $current_plugin_data Array with current plugin data. 267 * @param array $new_plugin_data Array with uploaded plugin data. 268 */ 269 return apply_filters( 'install_plugin_compare_table_ovewrite', $table, $current_plugin_data, $this->upgrader->new_plugin_data ); 270 } 141 271 } -
src/wp-admin/includes/class-plugin-upgrader.php
39 39 public $bulk = false; 40 40 41 41 /** 42 * New plugin info. 43 * 44 * @since 5.5.0 45 * @var array $new_plugin_data 46 * 47 * @see check_package() 48 */ 49 public $new_plugin_data = []; 50 51 /** 42 52 * Initialize the upgrade strings. 43 53 * 44 54 * @since 2.8.0 … … 54 64 $this->strings['process_failed'] = __( 'Plugin update failed.' ); 55 65 $this->strings['process_success'] = __( 'Plugin updated successfully.' ); 56 66 $this->strings['process_bulk_success'] = __( 'Plugins updated successfully.' ); 67 68 /* translators: 1: Plugin name, 2: Plugin version. */ 69 $this->strings['process_success_specific'] = __( 'Successfully installed the plugin <strong>%1$s %2$s</strong>.' ); 57 70 } 58 71 59 72 /** … … 67 80 $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '<span class="code">%s</span>' ); 68 81 $this->strings['unpack_package'] = __( 'Unpacking the package…' ); 69 82 $this->strings['installing_package'] = __( 'Installing the plugin…' ); 83 $this->strings['remove_old'] = __( 'Removing the current plugin…' ); 84 $this->strings['remove_old_failed'] = __( 'Could not remove the current plugin.' ); 70 85 $this->strings['no_files'] = __( 'The plugin contains no files.' ); 71 86 $this->strings['process_failed'] = __( 'Plugin installation failed.' ); 72 87 $this->strings['process_success'] = __( 'Plugin installed successfully.' ); 88 89 $this->strings['reuploading_plugin'] = __( 'Seems you have uploaded a plugin that is already installed.' ); 90 $this->strings['compare_before_overwrite'] = __( 'Plugin information:' ); 91 92 if ( 'update-plugin' === $this->skin->overwrite ) { 93 $this->strings['installing_package'] = __( 'Updating the plugin…' ); 94 $this->strings['process_failed'] = __( 'Plugin update failed.' ); 95 $this->strings['process_success'] = __( 'Plugin updated successfully.' ); 96 } 97 98 if ( 'downgrade-plugin' === $this->skin->overwrite ) { 99 $this->strings['installing_package'] = __( 'Downgrading the plugin…' ); 100 $this->strings['process_failed'] = __( 'Plugin downgrade failed.' ); 101 $this->strings['process_success'] = __( 'Plugin downgraded successfully.' ); 102 } 73 103 } 74 104 75 105 /** … … 88 118 * @return bool|WP_Error True if the installation was successful, false or a WP_Error otherwise. 89 119 */ 90 120 public function install( $package, $args = array() ) { 91 92 121 $defaults = array( 93 122 'clear_update_cache' => true, 123 'overwrite_package' => false, // Do not overwrite files. 94 124 ); 95 125 $parsed_args = wp_parse_args( $args, $defaults ); 96 126 … … 107 137 array( 108 138 'package' => $package, 109 139 'destination' => WP_PLUGIN_DIR, 110 'clear_destination' => false, // Do not overwrite files.140 'clear_destination' => $args['overwrite_package'], 111 141 'clear_working' => true, 112 142 'hook_extra' => array( 113 143 'type' => 'plugin', … … 126 156 // Force refresh of plugin update information. 127 157 wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); 128 158 159 if ( $parsed_args['overwrite_package'] ) { 160 /** 161 * Fires when the upgrader process a install forcing a package overwrite. 162 * 163 * @since 5.5.0 164 * 165 * @param string $package The package file. 166 * @param array $new_plugin_data The new plugin data. 167 * @param string $package_type The package type (plugin or theme). 168 */ 169 do_action( 'upgrader_overwrited_package', $package, $this->new_plugin_data, 'plugin' ); 170 } 171 129 172 return true; 130 173 } 131 174 … … 145 188 * @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise. 146 189 */ 147 190 public function upgrade( $plugin, $args = array() ) { 148 149 191 $defaults = array( 150 192 'clear_update_cache' => true, 151 193 ); … … 223 265 * @return array|false An array of results indexed by plugin file, or false if unable to connect to the filesystem. 224 266 */ 225 267 public function bulk_upgrade( $plugins, $args = array() ) { 226 227 268 $defaults = array( 228 269 'clear_update_cache' => true, 229 270 ); … … 349 390 public function check_package( $source ) { 350 391 global $wp_filesystem; 351 392 393 $this->new_plugin_data = []; 394 352 395 if ( is_wp_error( $source ) ) { 353 396 return $source; 354 397 } … … 359 402 } 360 403 361 404 // Check that the folder contains at least 1 valid plugin. 362 $plugins_found = false; 363 $files = glob( $working_directory . '*.php' ); 405 $files = glob( $working_directory . '*.php' ); 364 406 if ( $files ) { 365 407 foreach ( $files as $file ) { 366 408 $info = get_plugin_data( $file, false, false ); 367 409 if ( ! empty( $info['Name'] ) ) { 368 $ plugins_found = true;410 $this->new_plugin_data = $info; 369 411 break; 370 412 } 371 413 } 372 414 } 373 415 374 if ( ! $plugins_found) {416 if ( empty( $this->new_plugin_data ) ) { 375 417 return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) ); 376 418 } 377 419 -
src/wp-admin/includes/class-theme-installer-skin.php
18 18 class Theme_Installer_Skin extends WP_Upgrader_Skin { 19 19 public $api; 20 20 public $type; 21 public $url; 22 public $overwrite; 21 23 24 private $is_downgrading = false; 25 22 26 /** 23 27 * @param array $args 24 28 */ 25 29 public function __construct( $args = array() ) { 26 30 $defaults = array( 27 'type' => 'web', 28 'url' => '', 29 'theme' => '', 30 'nonce' => '', 31 'title' => '', 31 'type' => 'web', 32 'url' => '', 33 'theme' => '', 34 'nonce' => '', 35 'title' => '', 36 'overwrite' => '', 32 37 ); 33 38 $args = wp_parse_args( $args, $defaults ); 34 39 35 $this->type = $args['type']; 36 $this->api = isset( $args['api'] ) ? $args['api'] : array(); 40 $this->type = $args['type']; 41 $this->url = $args['url']; 42 $this->api = isset( $args['api'] ) ? $args['api'] : array(); 43 $this->overwrite = $args['overwrite']; 37 44 38 45 parent::__construct( $args ); 39 46 } … … 53 60 /** 54 61 */ 55 62 public function after() { 63 $compare_table = $this->compare_table(); 64 65 if ( $compare_table ) { 66 $this->feedback( 'compare_before_overwrite' ); 67 echo $compare_table; 68 69 $overwrite = 'update-theme'; 70 $label = __( 'Remove current and install the uploaded version' ); 71 72 if ( $this->is_downgrading ) { 73 $overwrite = 'downgrade-theme'; 74 75 if ( isset( $this->upgrader->new_theme_data['Version'] ) ) { 76 $label = sprintf( __( 'Remove current and install version %s' ), $this->upgrader->new_theme_data['Version'] ); 77 } 78 } 79 80 $install_actions = array( 81 'themes_page' => sprintf( 82 '<a href="%s" target="_parent">%s</a>', 83 self_admin_url( 'theme-install.php' ), 84 __( 'Cancel and go back' ) 85 ), 86 'ovewrite_theme' => sprintf( 87 '<a class="ovewrite-uploaded-theme" href="%s" target="_parent">%s</a>', 88 wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'theme-upload' ), 89 $label 90 ), 91 ); 92 93 $backup_warning = __( '<strong>Important:</strong> Before updating, please <a href="https://wordpress.org/support/article/wordpress-backups/">back up your database and files</a>.' ); 94 $this->feedback( '<div class="notice notice-warning inline"><p>' . $backup_warning . '</p></div>' ); 95 96 /** 97 * Filters the list of action links available following a single theme installation failed but ovewrite is allowed. 98 * 99 * @since 5.5.0 100 * 101 * @param string[] $install_actions Array of theme action links. 102 * @param object $api Object containing WordPress.org API theme data. 103 * @param array $new_theme_data Array with uploaded theme data. 104 */ 105 $install_actions = apply_filters( 'install_theme_ovewrite_actions', $install_actions, $this->api, $this->upgrader->new_theme_data ); 106 if ( ! empty( $install_actions ) ) { 107 $this->feedback( implode( ' | ', (array) $install_actions ) ); 108 } 109 110 return; 111 } 112 56 113 if ( empty( $this->upgrader->result['destination_name'] ) ) { 57 114 return; 58 115 } … … 130 187 131 188 if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) { 132 189 unset( $install_actions['activate'], $install_actions['preview'] ); 190 } elseif ( get_option( 'template' ) === $stylesheet ) { 191 unset( $install_actions['activate'] ); 133 192 } 134 193 135 194 /** … … 147 206 $this->feedback( implode( ' | ', (array) $install_actions ) ); 148 207 } 149 208 } 209 210 /** 211 * Create the compare table to show user information about overwrite theme on upload. 212 * 213 * @since 5.5.0 214 * 215 * @return string $table The table output. 216 */ 217 private function compare_table() { 218 if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) { 219 return ''; 220 } 221 222 $folder = $this->result->get_error_data( 'folder_exists' ); 223 $folder = rtrim( $folder, '/' ); 224 225 $current_theme_data = false; 226 $all_themes = wp_get_themes( array( 'errors' => null ) ); 227 foreach ( $all_themes as $theme ) { 228 if ( rtrim( $theme->get_stylesheet_directory(), '/' ) !== $folder ) { 229 continue; 230 } 231 232 $current_theme_data = $theme; 233 } 234 235 if ( empty( $current_theme_data ) || empty( $this->upgrader->new_theme_data ) ) { 236 return ''; 237 } 238 239 $this->is_downgrading = version_compare( $current_theme_data['Version'], $this->upgrader->new_theme_data['Version'], '>' ); 240 241 $is_invalid_parent = false; 242 if ( ! empty( $this->upgrader->new_theme_data['Template'] ) ) { 243 $is_invalid_parent = ! in_array( $this->upgrader->new_theme_data['Template'], array_keys( $all_themes ), true ); 244 } 245 246 $rows = array( 247 'Name' => __( 'Theme Name' ), 248 'Version' => __( 'Version' ), 249 'Author' => __( 'Author' ), 250 'RequiresWP' => __( 'Requires at least' ), 251 'RequiresPHP' => __( 'Requires PHP' ), 252 'Template' => __( 'Parent Theme' ), 253 ); 254 255 $table = '<table class="compare-themes-table"><tbody>'; 256 $table .= '<tr><th></th><th>' . esc_html( __( 'Current' ) ) . '</th><th>' . esc_html( __( 'Uploaded' ) ) . '</th></tr>'; 257 258 $is_same_theme = true; // Let's consider only these rows 259 foreach ( $rows as $field => $label ) { 260 $old_value = $current_theme_data->display( $field, false ); 261 $old_value = $old_value ? $old_value : '-'; 262 263 $new_value = ! empty( $this->upgrader->new_theme_data[ $field ] ) ? $this->upgrader->new_theme_data[ $field ] : '-'; 264 265 if ( $old_value === $new_value && '-' === $new_value && 'Template' === $field ) { 266 continue; 267 } 268 269 $is_same_theme = $is_same_theme && ( $old_value === $new_value ); 270 271 $diff_field = ( 'Version' !== $field && $new_value !== $old_value ); 272 $diff_version = ( 'Version' === $field && $this->is_downgrading ); 273 $invalid_parent = false; 274 275 if ( 'Template' === $field && $is_invalid_parent ) { 276 $invalid_parent = true; 277 $new_value .= ' ' . __( '(not found)' ); 278 } 279 280 $table .= ( $diff_field || $diff_version || $invalid_parent ) ? '<tr class="warning">' : '<tr>'; 281 $table .= '<td>' . $label . '</td><td>' . esc_html( $old_value ) . '</td><td>' . esc_html( $new_value ) . '</td></tr>'; 282 } 283 284 $table .= '</tbody></table>'; 285 286 if ( $is_same_theme ) { 287 $this->feedback( 'reuploading_theme' ); 288 } 289 290 // Check errors for current theme 291 if ( is_wp_error( $current_theme_data->errors() ) ) { 292 $this->feedback( 'current_theme_has_errors', $current_theme_data->errors()->get_error_message() ); 293 } 294 295 /** 296 * Filters the compare table output for overwrite a theme package on upload. 297 * 298 * @since 5.5.0 299 * 300 * @param string $table The output table with Name, Version, Author, RequiresWP and RequiresPHP info. 301 * @param array $current_theme_data Array with current theme data. 302 * @param array $new_theme_data Array with uploaded theme data. 303 */ 304 return apply_filters( 'install_theme_compare_table_ovewrite', $table, $current_theme_data, $this->upgrader->new_theme_data ); 305 } 306 150 307 } -
src/wp-admin/includes/class-theme-upgrader.php
38 38 public $bulk = false; 39 39 40 40 /** 41 * New theme info. 42 * 43 * @since 5.5.0 44 * @var array $new_theme_data 45 * 46 * @see check_package() 47 */ 48 public $new_theme_data = array(); 49 50 /** 41 51 * Initialize the upgrade strings. 42 52 * 43 53 * @since 2.8.0 … … 65 75 $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '<span class="code">%s</span>' ); 66 76 $this->strings['unpack_package'] = __( 'Unpacking the package…' ); 67 77 $this->strings['installing_package'] = __( 'Installing the theme…' ); 78 $this->strings['remove_old'] = __( 'Removing the old version of the theme…' ); 79 $this->strings['remove_old_failed'] = __( 'Could not remove the old theme.' ); 68 80 $this->strings['no_files'] = __( 'The theme contains no files.' ); 69 81 $this->strings['process_failed'] = __( 'Theme installation failed.' ); 70 82 $this->strings['process_success'] = __( 'Theme installed successfully.' ); … … 79 91 $this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, <strong>%1$s %2$s</strong>.' ); 80 92 /* translators: %s: Theme name. */ 81 93 $this->strings['parent_theme_not_found'] = sprintf( __( '<strong>The parent theme could not be found.</strong> You will need to install the parent theme, %s, before you can use this child theme.' ), '<strong>%s</strong>' ); 94 95 $this->strings['compare_before_overwrite'] = __( 'Theme information:' ); 96 $this->strings['reuploading_theme'] = __( 'Seems you have uploaded a theme that is already installed.' ); 97 $this->strings['current_theme_has_errors'] = __( 'The current theme has the follow error: "%s".' ); 98 99 if ( 'update-theme' === $this->skin->overwrite ) { 100 $this->strings['installing_package'] = __( 'Updating the theme…' ); 101 $this->strings['process_failed'] = __( 'Theme update failed.' ); 102 $this->strings['process_success'] = __( 'Theme updated successfully.' ); 103 } 104 105 if ( 'downgrade-theme' === $this->skin->overwrite ) { 106 $this->strings['installing_package'] = __( 'Downgrading the theme…' ); 107 $this->strings['process_failed'] = __( 'Theme downgrade failed.' ); 108 $this->strings['process_success'] = __( 'Theme downgraded successfully.' ); 109 } 82 110 } 83 111 84 112 /** … … 200 228 * @return bool|WP_Error True if the installation was successful, false or a WP_Error object otherwise. 201 229 */ 202 230 public function install( $package, $args = array() ) { 203 204 231 $defaults = array( 205 232 'clear_update_cache' => true, 233 'overwrite_package' => false, // Do not overwrite files. 206 234 ); 207 235 $parsed_args = wp_parse_args( $args, $defaults ); 208 236 … … 220 248 array( 221 249 'package' => $package, 222 250 'destination' => get_theme_root(), 223 'clear_destination' => false, // Do not overwrite files.251 'clear_destination' => $args['overwrite_package'], 224 252 'clear_working' => true, 225 253 'hook_extra' => array( 226 254 'type' => 'theme', … … 240 268 // Refresh the Theme Update information. 241 269 wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); 242 270 271 if ( $parsed_args['overwrite_package'] ) { 272 /** 273 * Fires when the upgrader process a install forcing a package overwrite. 274 * 275 * @since 5.5.0 276 * 277 * @param string $package The package file. 278 * @param array $new_plugin_data The new theme data. 279 * @param string $package_type The package type (theme or theme). 280 */ 281 do_action( 'upgrader_overwrited_package', $package, $this->new_theme_data, 'theme' ); 282 } 283 243 284 return true; 244 285 } 245 286 … … 259 300 * @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise. 260 301 */ 261 302 public function upgrade( $theme, $args = array() ) { 262 263 303 $defaults = array( 264 304 'clear_update_cache' => true, 265 305 ); … … 332 372 * @return array[]|false An array of results, or false if unable to connect to the filesystem. 333 373 */ 334 374 public function bulk_upgrade( $themes, $args = array() ) { 335 336 375 $defaults = array( 337 376 'clear_update_cache' => true, 338 377 ); … … 461 500 public function check_package( $source ) { 462 501 global $wp_filesystem; 463 502 503 $this->new_theme_data = array(); 504 464 505 if ( is_wp_error( $source ) ) { 465 506 return $source; 466 507 } … … 484 525 ); 485 526 } 486 527 528 // All these headers are needed on Theme_Installer_Skin::compare_table(). 487 529 $info = get_file_data( 488 530 $working_directory . 'style.css', 489 531 array( 490 'Name' => 'Theme Name', 491 'Template' => 'Template', 532 'Name' => 'Theme Name', 533 'Version' => 'Version', 534 'Author' => 'Author', 535 'Template' => 'Template', 536 'RequiresWP' => 'Requires at least', 537 'RequiresPHP' => 'Requires PHP', 492 538 ) 493 539 ); 494 540 … … 517 563 ); 518 564 } 519 565 566 $this->new_theme_data = $info; 520 567 return $source; 521 568 } 522 569 … … 640 687 * and the last result isn't set. 641 688 */ 642 689 public function theme_info( $theme = null ) { 643 644 690 if ( empty( $theme ) ) { 645 691 if ( ! empty( $this->result['destination_name'] ) ) { 646 692 $theme = $this->result['destination_name']; … … 648 694 return false; 649 695 } 650 696 } 651 return wp_get_theme( $theme ); 697 698 $theme = wp_get_theme( $theme ); 699 $theme->cache_delete(); 700 701 return $theme; 652 702 } 653 703 654 704 } -
src/wp-admin/includes/plugin-install.php
353 353 <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-plugin' ); ?>"> 354 354 <?php wp_nonce_field( 'plugin-upload' ); ?> 355 355 <label class="screen-reader-text" for="pluginzip"><?php _e( 'Plugin zip file' ); ?></label> 356 <input type="file" id="pluginzip" name="pluginzip" />356 <input type="file" id="pluginzip" name="pluginzip" accept=".zip" /> 357 357 <?php submit_button( __( 'Install Now' ), '', 'install-plugin-submit', false ); ?> 358 358 </form> 359 359 </div> -
src/wp-admin/includes/theme-install.php
183 183 <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-theme' ); ?>"> 184 184 <?php wp_nonce_field( 'theme-upload' ); ?> 185 185 <label class="screen-reader-text" for="themezip"><?php _e( 'Theme zip file' ); ?></label> 186 <input type="file" id="themezip" name="themezip" />186 <input type="file" id="themezip" name="themezip" accept=".zip"/> 187 187 <?php submit_button( __( 'Install Now' ), '', 'install-theme-submit', false ); ?> 188 188 </form> 189 189 <?php -
src/wp-admin/update.php
162 162 $url = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-plugin' ); 163 163 $type = 'upload'; // Install plugin type, From Web or an Upload. 164 164 165 $ upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );166 $ result = $upgrader->install( $file_upload->package );165 $overwrite = isset( $_GET['overwrite'] ) ? sanitize_text_field( $_GET['overwrite'] ) : ''; 166 $overwrite = in_array( $overwrite, array( 'update-plugin', 'downgrade-plugin' ), true ) ? $overwrite : ''; 167 167 168 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url', 'overwrite' ) ) ); 169 $result = $upgrader->install( $file_upload->package, [ 'overwrite_package' => $overwrite ] ); 170 168 171 if ( $result || is_wp_error( $result ) ) { 169 172 $file_upload->cleanup(); 170 173 } … … 282 285 $url = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-theme' ); 283 286 $type = 'upload'; // Install theme type, From Web or an Upload. 284 287 285 $ upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );286 $ result = $upgrader->install( $file_upload->package );288 $overwrite = isset( $_GET['overwrite'] ) ? sanitize_text_field( $_GET['overwrite'] ) : ''; 289 $overwrite = in_array( $overwrite, array( 'update-theme', 'downgrade-theme' ), true ) ? $overwrite : ''; 287 290 291 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url', 'overwrite' ) ) ); 292 $result = $upgrader->install( $file_upload->package, [ 'overwrite_package' => $overwrite ] ); 293 288 294 if ( $result || is_wp_error( $result ) ) { 289 295 $file_upload->cleanup(); 290 296 }