Ticket #11915: upload_upgrade.diff
File upload_upgrade.diff, 5.3 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/plugin-install.php
215 215 <?php wp_nonce_field( 'plugin-upload') ?> 216 216 <label class="screen-reader-text" for="pluginzip"><?php _e('Plugin zip file'); ?></label> 217 217 <input type="file" id="pluginzip" name="pluginzip" /> 218 <input type="checkbox" id="upgrade_checked" name="upgrade_checked" /> 219 <label for="upgrade_checked"><?php _e('Replace current plugin'); ?></label> 218 220 <input type="submit" class="button" value="<?php esc_attr_e('Install Now') ?>" /> 219 221 </form> 220 222 <?php -
wp-admin/includes/class-wp-upgrader.php
265 265 return $this->result; 266 266 } 267 267 268 /** 269 * Find out which plugin is in the working dir. 270 * 271 * Similar to get_plugins(), but in the working directory 272 * Should that function be adapted to this purpose? 273 * 274 * @param string $working_dir Mystery plugin directory. 275 * @return string|WP_Error The plugin in the directory or an error. 276 */ 277 function get_working_plugin( $working_dir ) { 278 global $wp_filesystem; 279 280 $working_files = $wp_filesystem->dirlist( $working_dir ); 281 $working_subdir = '.'; 282 $plugin_dir = basename( $working_dir ); 283 $plugins = array(); 284 if ( 1 == count( $working_files ) ) { 285 // Check for a subdirectory 286 $dir_names = array_keys( $working_files ); 287 if ( 'd' == $working_files[$dir_names[0]]['type'] ) { 288 $working_subdir = $plugin_dir = $dir_names[0]; 289 $working_files = $wp_filesystem->dirlist( trailingslashit( $working_dir ) . $working_subdir ); 290 } 291 } 292 if ( ! empty( $working_files ) ) { 293 foreach( $working_files as $file => $properties ) { 294 if ( substr( $file, -4 ) == '.php' ) { 295 $plugin_data = get_plugin_data( trailingslashit( $working_dir ) . $working_subdir . '/' . $file, false, false ); 296 297 if ( empty( $plugin_data['Name'] ) ) 298 continue; 299 300 $plugins[] = $plugin_dir . '/' . $file; 301 } 302 } 303 } 304 305 if ( count( $plugins ) != 1 ) { 306 // More trouble than it's worth handling multple plugins in a package? 307 return new WP_Error('bad_package', $this->strings['bad_package']); 308 } 309 310 return $plugins[0]; 311 } 312 268 313 function run($options) { 269 314 270 315 $defaults = array( 'package' => '', //Please always pass this. … … 272 317 'clear_destination' => false, 273 318 'clear_working' => true, 274 319 'is_multi' => false, 275 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters. 320 'hook_extra' => array(), //Pass any extra $hook_extra args here, this will be passed to any hooked filters. 321 'is_upload_upgrade' => false 276 322 ); 277 323 278 324 $options = wp_parse_args($options, $defaults); … … 307 353 return $working_dir; 308 354 } 309 355 356 if ( $is_upload_upgrade and empty( $hook_extra ) ) { 357 // Doesn't work on plugins without their own subdirectory? 358 $plugin = $this->get_working_plugin( $working_dir ); 359 360 if ( is_wp_error($plugin) ) { 361 $this->skin->error($plugin); 362 return $plugin; 363 } 364 365 // This upgrade method depends on this identification of the plugin for hooks 366 $hook_extra = array( 'plugin' => $plugin ); 367 } 368 310 369 //With the given options, this installs it to the destination directory. 311 370 $result = $this->install_package( array( 312 371 'source' => $working_dir, … … 402 461 403 462 } 404 463 464 function upload_upgrade($package) { 465 466 $this->init(); 467 $this->upgrade_strings(); 468 469 add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2); 470 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); 471 472 $this->run(array( 473 'package' => $package, 474 'destination' => WP_PLUGIN_DIR, 475 'clear_destination' => true, 476 'clear_working' => true, 477 'hook_extra' => array(), // run must supply this after looking in the package 478 'is_upload_upgrade' => true 479 )); 480 481 // Cleanup our hooks, incase something else does a upgrade on this connection. 482 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade')); 483 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); 484 485 if ( ! $this->result || is_wp_error($this->result) ) 486 return $this->result; 487 488 // Force refresh of plugin update information 489 delete_site_transient('update_plugins'); 490 } 491 405 492 function upgrade($plugin) { 406 493 407 494 $this->init(); -
wp-admin/update.php
110 110 $type = 'upload'; //Install plugin type, From Web or an Upload. 111 111 112 112 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) ); 113 $upgrader->install( $file_upload->package ); 113 if ( isset( $_REQUEST['upgrade_checked'] ) ) 114 $upgrader->upload_upgrade( $file_upload->package ); 115 else 116 $upgrader->install( $file_upload->package ); 114 117 115 118 include('admin-footer.php'); 116 119 … … 195 198 } else { 196 199 do_action('update-custom_' . $action); 197 200 } 198 } 199 No newline at end of file 201 }