503 * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade(). |
503 * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade(). |
504 * |
504 * |
505 * @since 2.8.0 |
505 * @since 2.8.0 |
506 * @since 4.1.0 Added a return value. |
506 * @since 4.1.0 Added a return value. |
507 * |
507 * |
508 * @param bool|WP_Error $return Upgrade offer return. |
508 * @param bool|WP_Error $response The installation response before the installation has started. |
509 * @param array $plugin Plugin package arguments. |
509 * @param array $plugin Plugin package arguments. |
510 * @return bool|WP_Error The passed in $return param or WP_Error. |
510 * @return bool|WP_Error The original `$response` parameter or WP_Error. |
511 */ |
511 */ |
512 public function deactivate_plugin_before_upgrade( $return, $plugin ) { |
512 public function deactivate_plugin_before_upgrade( $response, $plugin ) { |
513 |
513 |
514 if ( is_wp_error( $return ) ) { // Bypass. |
514 if ( is_wp_error( $response ) ) { // Bypass. |
515 return $return; |
515 return $response; |
516 } |
516 } |
517 |
517 |
518 // When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it. |
518 // When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it. |
519 if ( wp_doing_cron() ) { |
519 if ( wp_doing_cron() ) { |
520 return $return; |
520 return $response; |
521 } |
521 } |
522 |
522 |
523 $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; |
523 $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; |
524 if ( empty( $plugin ) ) { |
524 if ( empty( $plugin ) ) { |
525 return new WP_Error( 'bad_request', $this->strings['bad_request'] ); |
525 return new WP_Error( 'bad_request', $this->strings['bad_request'] ); |
528 if ( is_plugin_active( $plugin ) ) { |
528 if ( is_plugin_active( $plugin ) ) { |
529 // Deactivate the plugin silently, Prevent deactivation hooks from running. |
529 // Deactivate the plugin silently, Prevent deactivation hooks from running. |
530 deactivate_plugins( $plugin, true ); |
530 deactivate_plugins( $plugin, true ); |
531 } |
531 } |
532 |
532 |
533 return $return; |
533 return $response; |
534 } |
534 } |
535 |
535 |
536 /** |
536 /** |
537 * Turns on maintenance mode before attempting to background update an active plugin. |
537 * Turns on maintenance mode before attempting to background update an active plugin. |
538 * |
538 * |
539 * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade(). |
539 * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade(). |
540 * |
540 * |
541 * @since 5.4.0 |
541 * @since 5.4.0 |
542 * |
542 * |
543 * @param bool|WP_Error $return Upgrade offer return. |
543 * @param bool|WP_Error $response The installation response before the installation has started. |
544 * @param array $plugin Plugin package arguments. |
544 * @param array $plugin Plugin package arguments. |
545 * @return bool|WP_Error The passed in $return param or WP_Error. |
545 * @return bool|WP_Error The original `$response` parameter or WP_Error. |
546 */ |
546 */ |
547 public function active_before( $return, $plugin ) { |
547 public function active_before( $response, $plugin ) { |
548 if ( is_wp_error( $return ) ) { |
548 if ( is_wp_error( $response ) ) { |
549 return $return; |
549 return $response; |
550 } |
550 } |
551 |
551 |
552 // Only enable maintenance mode when in cron (background update). |
552 // Only enable maintenance mode when in cron (background update). |
553 if ( ! wp_doing_cron() ) { |
553 if ( ! wp_doing_cron() ) { |
554 return $return; |
554 return $response; |
555 } |
555 } |
556 |
556 |
557 $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; |
557 $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; |
558 |
558 |
559 // Only run if plugin is active. |
559 // Only run if plugin is active. |
560 if ( ! is_plugin_active( $plugin ) ) { |
560 if ( ! is_plugin_active( $plugin ) ) { |
561 return $return; |
561 return $response; |
562 } |
562 } |
563 |
563 |
564 // Change to maintenance mode. Bulk edit handles this separately. |
564 // Change to maintenance mode. Bulk edit handles this separately. |
565 if ( ! $this->bulk ) { |
565 if ( ! $this->bulk ) { |
566 $this->maintenance_mode( true ); |
566 $this->maintenance_mode( true ); |
567 } |
567 } |
568 |
568 |
569 return $return; |
569 return $response; |
570 } |
570 } |
571 |
571 |
572 /** |
572 /** |
573 * Turns off maintenance mode after upgrading an active plugin. |
573 * Turns off maintenance mode after upgrading an active plugin. |
574 * |
574 * |
575 * Hooked to the {@see 'upgrader_post_install'} filter by Plugin_Upgrader::upgrade(). |
575 * Hooked to the {@see 'upgrader_post_install'} filter by Plugin_Upgrader::upgrade(). |
576 * |
576 * |
577 * @since 5.4.0 |
577 * @since 5.4.0 |
578 * |
578 * |
579 * @param bool|WP_Error $return Upgrade offer return. |
579 * @param bool|WP_Error $response The installation response after the installation has finished. |
580 * @param array $plugin Plugin package arguments. |
580 * @param array $plugin Plugin package arguments. |
581 * @return bool|WP_Error The passed in $return param or WP_Error. |
581 * @return bool|WP_Error The original `$response` parameter or WP_Error. |
582 */ |
582 */ |
583 public function active_after( $return, $plugin ) { |
583 public function active_after( $response, $plugin ) { |
584 if ( is_wp_error( $return ) ) { |
584 if ( is_wp_error( $response ) ) { |
585 return $return; |
585 return $response; |
586 } |
586 } |
587 |
587 |
588 // Only disable maintenance mode when in cron (background update). |
588 // Only disable maintenance mode when in cron (background update). |
589 if ( ! wp_doing_cron() ) { |
589 if ( ! wp_doing_cron() ) { |
590 return $return; |
590 return $response; |
591 } |
591 } |
592 |
592 |
593 $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; |
593 $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; |
594 |
594 |
595 // Only run if plugin is active |
595 // Only run if plugin is active. |
596 if ( ! is_plugin_active( $plugin ) ) { |
596 if ( ! is_plugin_active( $plugin ) ) { |
597 return $return; |
597 return $response; |
598 } |
598 } |
599 |
599 |
600 // Time to remove maintenance mode. Bulk edit handles this separately. |
600 // Time to remove maintenance mode. Bulk edit handles this separately. |
601 if ( ! $this->bulk ) { |
601 if ( ! $this->bulk ) { |
602 $this->maintenance_mode( false ); |
602 $this->maintenance_mode( false ); |
603 } |
603 } |
604 |
604 |
605 return $return; |
605 return $response; |
606 } |
606 } |
607 |
607 |
608 /** |
608 /** |
609 * Deletes the old plugin during an upgrade. |
609 * Deletes the old plugin during an upgrade. |
610 * |
610 * |