Ticket #9757: upload_upgrade.diff
File upload_upgrade.diff, 5.4 KB (added by , 14 years ago) |
---|
-
wp-admin/includes/plugin.php
212 212 * @since 1.5.0 213 213 * 214 214 * @param string $plugin_folder Optional. Relative path to single plugin folder. 215 * @param string $plugin_root Optional. Allows data to be retrieved for plugin(s) in a working directory (e.g. for zip upgrades) 215 216 * @return array Key is the plugin file path and the value is an array of the plugin data. 216 217 */ 217 function get_plugins($plugin_folder = '' ) {218 function get_plugins($plugin_folder = '', $plugin_root = '') { 218 219 219 if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins') )220 if ( empty( $plugin_root ) and ! $cache_plugins = wp_cache_get('plugins', 'plugins') ) 220 221 $cache_plugins = array(); 221 222 222 223 if ( isset($cache_plugins[ $plugin_folder ]) ) 223 224 return $cache_plugins[ $plugin_folder ]; 224 225 225 226 $wp_plugins = array (); 226 $plugin_root = WP_PLUGIN_DIR; 227 if ( empty($plugin_root ) ) 228 $plugin_root = WP_PLUGIN_DIR; 227 229 if ( !empty($plugin_folder) ) 228 230 $plugin_root .= $plugin_folder; 229 231 -
wp-admin/includes/plugin-install.php
147 147 <?php wp_nonce_field( 'plugin-upload') ?> 148 148 <label class="screen-reader-text" for="pluginzip"><?php _e('Plugin zip file'); ?></label> 149 149 <input type="file" id="pluginzip" name="pluginzip" /> 150 <input type="checkbox" id="upgrade_checked" name="upgrade_checked" /> 151 <label for="upgrade_checked"><?php _e('Replace current plugin'); ?></label> 150 152 <input type="submit" class="button" value="<?php esc_attr_e('Install Now') ?>" /> 151 153 </form> 152 154 <?php -
wp-admin/includes/class-wp-upgrader.php
270 270 'clear_destination' => false, 271 271 'clear_working' => true, 272 272 'is_multi' => false, 273 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters. 273 'hook_extra' => array(), //Pass any extra $hook_extra args here, this will be passed to any hooked filters. 274 'is_upload_upgrade' => false 274 275 ); 275 276 276 277 $options = wp_parse_args($options, $defaults); … … 309 310 return $working_dir; 310 311 } 311 312 313 if ( $is_upload_upgrade and empty( $hook_extra ) ) { 314 315 $plugin = get_plugins( '', $working_dir ); 316 if ( is_wp_error($plugin) ) { 317 $this->skin->error($plugin); 318 return $plugin; 319 } 320 // Not (yet?) attempting to handle multple plugins in a package 321 if ( count( $plugin ) != 1 ) 322 return $this->skin( new WP_Error('bad_package', $this->strings['bad_package']) ); 323 324 // Make sure the plugin name matches the one it will replace 325 $installed_plugins = get_plugins(); 326 $plugin_paths = array_keys( $plugin ); 327 $plugin_path = $plugin_paths[0]; 328 if ( ! isset( $installed_plugins[$plugin_path] ) or $installed_plugins[$plugin_path]['Name'] != $plugin[$plugin_path]['Name'] ) { 329 // May want a different error message for this 330 $error = new WP_Error( 'bad_package', $this->strings['bad_package'] ); 331 $this->skin->error( $error ); 332 return $error; 333 } 334 335 // This upgrade method depends on this identification of the plugin for hooks 336 $hook_extra = array( 'plugin' => $plugin_path ); 337 } 338 312 339 //With the given options, this installs it to the destination directory. 313 340 $result = $this->install_package( array( 314 341 'source' => $working_dir, … … 404 431 405 432 } 406 433 434 function upload_upgrade($package) { 435 436 $this->init(); 437 $this->upgrade_strings(); 438 439 add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2); 440 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); 441 442 $this->run(array( 443 'package' => $package, 444 'destination' => WP_PLUGIN_DIR, 445 'clear_destination' => true, 446 'clear_working' => true, 447 'hook_extra' => array(), // run must supply this after looking in the package for plugin name 448 'is_upload_upgrade' => true 449 )); 450 451 // Cleanup our hooks, in case something else does a upgrade on this connection. 452 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade')); 453 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); 454 455 if ( ! $this->result || is_wp_error($this->result) ) 456 return $this->result; 457 458 // Force refresh of plugin update information 459 delete_site_transient('update_plugins'); 460 } 461 407 462 function upgrade($plugin) { 408 463 409 464 $this->init(); -
wp-admin/update.php
138 138 $type = 'upload'; //Install plugin type, From Web or an Upload. 139 139 140 140 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) ); 141 $upgrader->install( $file_upload->package ); 141 if ( isset( $_REQUEST['upgrade_checked'] ) ) 142 $upgrader->upload_upgrade( $file_upload->package ); 143 else 144 $upgrader->install( $file_upload->package ); 142 145 143 146 include(ABSPATH . 'wp-admin/admin-footer.php'); 144 147