Ticket #37531: 37531.3.patch
File 37531.3.patch, 12.2 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
3345 3345 wp_send_json_error( $status ); 3346 3346 } 3347 3347 3348 $upgrader = new Theme_Upgrader( new Automatic_Upgrader_Skin() ); 3348 $skin = new WP_Ajax_Upgrader_Skin(); 3349 $upgrader = new Theme_Upgrader( $skin ); 3349 3350 $result = $upgrader->install( $api->download_link ); 3350 3351 3351 3352 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3352 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3353 $status['debug'] = $skin->get_upgrade_messages(); 3353 3354 } 3354 3355 3355 3356 if ( is_wp_error( $result ) ) { 3357 $status['errorCode'] = $result->get_error_code(); 3356 3358 $status['errorMessage'] = $result->get_error_message(); 3357 3359 wp_send_json_error( $status ); 3360 } elseif ( is_wp_error( $skin->result ) ) { 3361 $status['errorCode'] = $skin->result->get_error_code(); 3362 $status['errorMessage'] = $skin->result->get_error_message(); 3363 wp_send_json_error( $status ); 3364 } elseif ( $skin->get_errors()->get_error_code() ) { 3365 $errors = $skin->get_errors(); 3366 3367 $messages = array(); 3368 foreach ( $errors->get_error_codes() as $error_code ) { 3369 if ( $errors->get_error_data( $error_code ) && is_string( $errors->get_error_data( $error_code ) ) ) { 3370 $messages[] = $errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $errors->get_error_data( $error_code ) ) ); 3371 } else { 3372 $messages[] = $errors->get_error_message( $error_code ); 3373 } 3374 } 3375 3376 $status['errorMessage'] = implode( ', ', $messages ); 3377 wp_send_json_error( $status ); 3358 3378 } elseif ( is_null( $result ) ) { 3359 3379 global $wp_filesystem; 3360 3380 … … 3363 3383 3364 3384 // Pass through the error from WP_Filesystem if one was raised. 3365 3385 if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { 3386 $status['errorCode'] = $wp_filesystem->errors->get_error_code(); 3366 3387 $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); 3367 3388 } 3368 3389 … … 3437 3458 wp_update_themes(); 3438 3459 } 3439 3460 3440 $upgrader = new Theme_Upgrader( new Automatic_Upgrader_Skin() ); 3461 $skin = new WP_Ajax_Upgrader_Skin(); 3462 $upgrader = new Theme_Upgrader( $skin ); 3441 3463 $result = $upgrader->bulk_upgrade( array( $stylesheet ) ); 3442 3464 3443 3465 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3444 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3466 $status['debug'] = $skin->get_upgrade_messages(); 3445 3467 } 3446 3468 3447 if ( is_array( $result ) && ! empty( $result[ $stylesheet ] ) ) { 3469 if ( is_wp_error( $result ) ) { 3470 $status['errorCode'] = $result->get_error_code(); 3471 $status['errorMessage'] = $result->get_error_message(); 3472 wp_send_json_error( $status ); 3473 } elseif ( is_wp_error( $skin->result ) ) { 3474 $status['errorCode'] = $skin->result->get_error_code(); 3475 $status['errorMessage'] = $skin->result->get_error_message(); 3476 wp_send_json_error( $status ); 3477 } elseif ( $skin->get_errors()->get_error_code() ) { 3478 $errors = $skin->get_errors(); 3448 3479 3480 $messages = array(); 3481 foreach ( $errors->get_error_codes() as $error_code ) { 3482 if ( $errors->get_error_data( $error_code ) && is_string( $errors->get_error_data( $error_code ) ) ) { 3483 $messages[] = $errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $errors->get_error_data( $error_code ) ) ); 3484 } else { 3485 $messages[] = $errors->get_error_message( $error_code ); 3486 } 3487 } 3488 3489 $status['errorMessage'] = implode( ', ', $messages ); 3490 wp_send_json_error( $status ); 3491 } elseif ( is_array( $result ) && ! empty( $result[ $stylesheet ] ) ) { 3492 3449 3493 // Theme is already at the latest version. 3450 3494 if ( true === $result[ $stylesheet ] ) { 3451 3495 $status['errorMessage'] = $upgrader->strings['up_to_date']; … … 3458 3502 } 3459 3503 3460 3504 wp_send_json_success( $status ); 3461 } elseif ( is_wp_error( $upgrader->skin->result ) ) {3462 $status['errorCode'] = $upgrader->skin->result->get_error_code();3463 $status['errorMessage'] = $upgrader->skin->result->get_error_message();3464 wp_send_json_error( $status );3465 3505 } elseif ( false === $result ) { 3466 3506 global $wp_filesystem; 3467 3507 … … 3470 3510 3471 3511 // Pass through the error from WP_Filesystem if one was raised. 3472 3512 if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { 3513 $status['errorCode'] = $wp_filesystem->errors->get_error_code(); 3473 3514 $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); 3474 3515 } 3475 3516 … … 3594 3635 3595 3636 $status['pluginName'] = $api->name; 3596 3637 3597 $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); 3638 $skin = new WP_Ajax_Upgrader_Skin(); 3639 $upgrader = new Plugin_Upgrader( $skin ); 3598 3640 $result = $upgrader->install( $api->download_link ); 3599 3641 3600 3642 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3601 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3643 $status['debug'] = $skin->get_upgrade_messages(); 3602 3644 } 3603 3645 3604 3646 if ( is_wp_error( $result ) ) { 3647 $status['errorCode'] = $result->get_error_code(); 3605 3648 $status['errorMessage'] = $result->get_error_message(); 3606 3649 wp_send_json_error( $status ); 3650 } elseif ( is_wp_error( $skin->result ) ) { 3651 $status['errorCode'] = $skin->result->get_error_code(); 3652 $status['errorMessage'] = $skin->result->get_error_message(); 3653 wp_send_json_error( $status ); 3654 } elseif ( $skin->get_errors()->get_error_code() ) { 3655 $errors = $skin->get_errors(); 3656 3657 $messages = array(); 3658 foreach ( $errors->get_error_codes() as $error_code ) { 3659 if ( $errors->get_error_data( $error_code ) && is_string( $errors->get_error_data( $error_code ) ) ) { 3660 $messages[] = $errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $errors->get_error_data( $error_code ) ) ); 3661 } else { 3662 $messages[] = $errors->get_error_message( $error_code ); 3663 } 3664 } 3665 3666 $status['errorMessage'] = implode( ', ', $messages ); 3667 wp_send_json_error( $status ); 3607 3668 } elseif ( is_null( $result ) ) { 3608 3669 global $wp_filesystem; 3609 3670 … … 3612 3673 3613 3674 // Pass through the error from WP_Filesystem if one was raised. 3614 3675 if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { 3676 $status['errorCode'] = $wp_filesystem->errors->get_error_code(); 3615 3677 $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); 3616 3678 } 3617 3679 … … 3680 3742 3681 3743 wp_update_plugins(); 3682 3744 3683 $skin = new Automatic_Upgrader_Skin();3745 $skin = new WP_Ajax_Upgrader_Skin(); 3684 3746 $upgrader = new Plugin_Upgrader( $skin ); 3685 3747 $result = $upgrader->bulk_upgrade( array( $plugin ) ); 3686 3748 3687 3749 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3688 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3750 $status['debug'] = $skin->get_upgrade_messages(); 3689 3751 } 3690 3752 3691 if ( is_array( $result ) && empty( $result[ $plugin ] ) && is_wp_error( $skin->result ) ) { 3692 $result = $skin->result; 3693 } 3753 if ( is_wp_error( $result ) ) { 3754 $status['errorCode'] = $result->get_error_code(); 3755 $status['errorMessage'] = $result->get_error_message(); 3756 wp_send_json_error( $status ); 3757 } elseif ( is_wp_error( $skin->result ) ) { 3758 $status['errorCode'] = $skin->result->get_error_code(); 3759 $status['errorMessage'] = $skin->result->get_error_message(); 3760 wp_send_json_error( $status ); 3761 } elseif ( $skin->get_errors()->get_error_code() ) { 3762 $errors = $skin->get_errors(); 3694 3763 3695 if ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) { 3764 $messages = array(); 3765 foreach ( $errors->get_error_codes() as $error_code ) { 3766 if ( $errors->get_error_data( $error_code ) && is_string( $errors->get_error_data( $error_code ) ) ) { 3767 $messages[] = $errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $errors->get_error_data( $error_code ) ) ); 3768 } else { 3769 $messages[] = $errors->get_error_message( $error_code ); 3770 } 3771 } 3772 3773 $status['errorMessage'] = implode( ', ', $messages ); 3774 wp_send_json_error( $status ); 3775 } elseif ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) { 3696 3776 $plugin_update_data = current( $result ); 3697 3777 3698 3778 /* … … 3716 3796 $status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); 3717 3797 } 3718 3798 wp_send_json_success( $status ); 3719 } elseif ( is_wp_error( $result ) ) {3720 $status['errorMessage'] = $result->get_error_message();3721 wp_send_json_error( $status );3722 3799 } elseif ( false === $result ) { 3723 3800 global $wp_filesystem; 3724 3801 -
src/wp-admin/includes/class-wp-ajax-upgrader-skin.php
1 <?php 2 /** 3 * Upgrader API: WP_Ajax_Upgrader_Skin class 4 * 5 * @package WordPress 6 * @subpackage Upgrader 7 * @since 4.6.0 8 */ 9 10 /** 11 * Upgrader Skin for Ajax WordPress Upgrades 12 * 13 * This skin is designed to be used for Ajax updates. 14 * 15 * @since 4.6.0 16 * 17 * @see Automatic_Upgrader_Skin 18 */ 19 class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin { 20 /** 21 * Holds the WP_Error object. 22 * 23 * @since 4.6.0 24 * @access protected 25 * 26 * @var null|WP_Error 27 */ 28 protected $errors = null; 29 30 /** 31 * Retrieves the list of errors. 32 * 33 * @since 4.6.0 34 * @access public 35 * 36 * @param array $args 37 */ 38 public function __construct( $args = array() ) { 39 parent::__construct( $args ); 40 41 $this->errors = new WP_Error(); 42 } 43 44 /** 45 * Retrieves the list of errors. 46 * 47 * @since 4.6.0 48 * @access public 49 * 50 * @return WP_Error Errors during an upgrade. 51 */ 52 public function get_errors() { 53 return $this->errors; 54 } 55 56 /** 57 * Stores a log entry for an error. 58 * 59 * @since 4.6.0 60 * @access public 61 * 62 * @param string|WP_Error $errors 63 */ 64 public function error( $errors ) { 65 if ( is_string( $errors ) ) { 66 $string = $errors; 67 if ( ! empty( $this->upgrader->strings[ $string ] ) ) { 68 $string = $this->upgrader->strings[ $string ]; 69 } 70 71 if ( false !== strpos( $string, '%' ) ) { 72 $args = func_get_args(); 73 $args = array_splice( $args, 1 ); 74 if ( ! empty( $args ) ) { 75 $string = vsprintf( $string, $args ); 76 } 77 } 78 79 // Count existing errors to generate an unique error code. 80 $errors_count = count( $errors->get_error_codes() ); 81 $this->errors->add( 'unknown_error_' . $errors_count + 1 , $string ); 82 } elseif ( is_wp_error( $errors ) ) { 83 foreach ( $errors->get_error_codes() as $error_code ) { 84 $this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) ); 85 } 86 } 87 88 $args = func_get_args(); 89 call_user_func_array( array( $this, 'parent::error' ), $args ); 90 } 91 92 /** 93 * Stores a log entry. 94 * 95 * @since 4.6.0 96 * @access public 97 * 98 * @param string|array|WP_Error $data 99 */ 100 public function feedback( $data ) { 101 if ( is_wp_error( $data ) ) { 102 foreach ( $data->get_error_codes() as $error_code ) { 103 $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) ); 104 } 105 } 106 107 $args = func_get_args(); 108 call_user_func_array( array( $this, 'parent::feedback' ), $args ); 109 } 110 } -
src/wp-admin/includes/class-wp-upgrader-skins.php
36 36 37 37 /** Automatic_Upgrader_Skin class */ 38 38 require_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php'; 39 40 /** WP_Ajax_Upgrader_Skin class */ 41 require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; -
src/wp-admin/includes/class-wp-upgrader.php
39 39 /** Automatic_Upgrader_Skin class */ 40 40 require_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php'; 41 41 42 /** WP_Ajax_Upgrader_Skin class */ 43 require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; 44 42 45 /** 43 46 * Core class used for upgrading/installing a local set of files via 44 47 * the Filesystem Abstraction classes from a Zip file.