Ticket #49400: 49400.1.patch
File 49400.1.patch, 5.1 KB (added by , 4 years ago) |
---|
-
src/wp-admin/includes/class-plugin-upgrader.php
167 167 $r = $current->response[ $plugin ]; 168 168 169 169 add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 ); 170 add_filter( 'upgrader_pre_install', array( $this, 'active_before' ), 10, 2 ); 170 171 add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 ); 172 add_filter( 'upgrader_post_install', array( $this, 'active_after' ), 10, 2 ); 171 173 // There's a Trac ticket to move up the directory for zips which are made a bit differently, useful for non-.org plugins. 172 174 // 'source_selection' => array( $this, 'source_selection' ), 173 175 if ( $parsed_args['clear_update_cache'] ) { … … 192 194 // Cleanup our hooks, in case something else does a upgrade on this connection. 193 195 remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 ); 194 196 remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) ); 197 remove_filter( 'upgrader_pre_install', array( $this, 'active_before' ) ); 195 198 remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) ); 199 remove_filter( 'upgrader_post_install', array( $this, 'active_after' ) ); 196 200 197 201 if ( ! $this->result || is_wp_error( $this->result ) ) { 198 202 return $this->result; … … 411 415 * @since 2.8.0 412 416 * @since 4.1.0 Added a return value. 413 417 * 414 * @param bool|WP_Error 415 * @param array 418 * @param bool|WP_Error $return Upgrade offer return. 419 * @param array $plugin Plugin package arguments. 416 420 * @return bool|WP_Error The passed in $return param or WP_Error. 417 421 */ 418 422 public function deactivate_plugin_before_upgrade( $return, $plugin ) { … … 440 444 } 441 445 442 446 /** 447 * Turn on maintenance mode before attempting to background update an active plugin. 448 * 449 * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade(). 450 * 451 * @since 5.4.0 452 * 453 * @param bool|WP_Error $return Upgrade offer return. 454 * @param array $plugin Plugin package arguments. 455 * @return bool|WP_Error The passed in $return param or WP_Error. 456 */ 457 public function active_before( $return, $plugin ) { 458 if ( is_wp_error( $return ) ) { 459 return $return; 460 } 461 462 // Only enable maintenance mode when in cron (background update). 463 if ( ! wp_doing_cron() ) { 464 return $return; 465 } 466 467 $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; 468 469 if ( ! is_plugin_active( $plugin ) ) { // If not active. 470 return $return; 471 } 472 473 // Bulk edit handles maintenance mode separately. 474 if ( ! $this->bulk ) { 475 $this->maintenance_mode( true ); 476 } 477 478 return $return; 479 } 480 481 /** 482 * Turn off maintenance mode after upgrading an active plugin. 483 * 484 * Hooked to the {@see 'upgrader_post_install'} filter by Plugin_Upgrader::upgrade(). 485 * 486 * @since 5.4.0 487 * 488 * @param bool|WP_Error $return Upgrade offer return. 489 * @param array $plugin Plugin package arguments. 490 * @return bool|WP_Error The passed in $return param or WP_Error. 491 */ 492 public function active_after( $return, $plugin ) { 493 if ( is_wp_error( $return ) ) { 494 return $return; 495 } 496 497 // Only enable maintenance mode when in cron (background update). 498 if ( ! wp_doing_cron() ) { 499 return $return; 500 } 501 502 $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; 503 504 if ( ! is_plugin_active( $plugin ) ) { // If not active. 505 return $return; 506 } 507 508 // Bulk edit handles maintenance mode separately. 509 if ( ! $this->bulk ) { 510 $this->maintenance_mode( false ); 511 } 512 513 return $return; 514 } 515 516 /** 443 517 * Delete the old plugin during an upgrade. 444 518 * 445 519 * Hooked to the {@see 'upgrader_clear_destination'} filter by … … 449 523 * 450 524 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. 451 525 * 452 * @param bool|WP_Error $removed 453 * @param string $local_destination 454 * @param string $remote_destination 455 * @param array $plugin 526 * @param bool|WP_Error $removed Whether the destination was cleared. true on success, WP_Error on failure. 527 * @param string $local_destination The local package destination. 528 * @param string $remote_destination The remote package destination. 529 * @param array $plugin Extra arguments passed to hooked filters. 456 530 * @return bool|WP_Error 457 531 */ 458 532 public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) { … … 476 550 477 551 // If plugin is in its own directory, recursively delete the directory. 478 552 // Base check on if plugin includes directory separator AND that it's not the root plugin folder. 479 if ( strpos( $plugin, '/' ) && $this_plugin_dir != $plugins_dir ) {553 if ( strpos( $plugin, '/' ) && $this_plugin_dir !== $plugins_dir ) { 480 554 $deleted = $wp_filesystem->delete( $this_plugin_dir, true ); 481 555 } else { 482 556 $deleted = $wp_filesystem->delete( $plugins_dir . $plugin );