Ticket #37531: 37531.5.patch
File 37531.5.patch, 13.0 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 $status['errorMessage'] = $skin->get_error_messages(); 3366 wp_send_json_error( $status ); 3358 3367 } elseif ( is_null( $result ) ) { 3359 3368 global $wp_filesystem; 3360 3369 … … 3363 3372 3364 3373 // Pass through the error from WP_Filesystem if one was raised. 3365 3374 if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { 3375 $status['errorCode'] = $wp_filesystem->errors->get_error_code(); 3366 3376 $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); 3367 3377 } 3368 3378 … … 3437 3447 wp_update_themes(); 3438 3448 } 3439 3449 3440 $upgrader = new Theme_Upgrader( new Automatic_Upgrader_Skin() ); 3450 $skin = new WP_Ajax_Upgrader_Skin(); 3451 $upgrader = new Theme_Upgrader( $skin ); 3441 3452 $result = $upgrader->bulk_upgrade( array( $stylesheet ) ); 3442 3453 3443 3454 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3444 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3455 $status['debug'] = $skin->get_upgrade_messages(); 3445 3456 } 3446 3457 3447 if ( is_array( $result ) && ! empty( $result[ $stylesheet ] ) ) { 3458 if ( is_wp_error( $result ) ) { 3459 $status['errorCode'] = $result->get_error_code(); 3460 $status['errorMessage'] = $result->get_error_message(); 3461 wp_send_json_error( $status ); 3462 } elseif ( is_wp_error( $skin->result ) ) { 3463 $status['errorCode'] = $skin->result->get_error_code(); 3464 $status['errorMessage'] = $skin->result->get_error_message(); 3465 wp_send_json_error( $status ); 3466 } elseif ( $skin->get_errors()->get_error_code() ) { 3467 $status['errorMessage'] = $skin->get_error_messages(); 3468 wp_send_json_error( $status ); 3469 } elseif ( is_array( $result ) && ! empty( $result[ $stylesheet ] ) ) { 3448 3470 3449 3471 // Theme is already at the latest version. 3450 3472 if ( true === $result[ $stylesheet ] ) { … … 3458 3480 } 3459 3481 3460 3482 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 3483 } elseif ( false === $result ) { 3466 3484 global $wp_filesystem; 3467 3485 … … 3470 3488 3471 3489 // Pass through the error from WP_Filesystem if one was raised. 3472 3490 if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { 3491 $status['errorCode'] = $wp_filesystem->errors->get_error_code(); 3473 3492 $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); 3474 3493 } 3475 3494 … … 3594 3613 3595 3614 $status['pluginName'] = $api->name; 3596 3615 3597 $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); 3616 $skin = new WP_Ajax_Upgrader_Skin(); 3617 $upgrader = new Plugin_Upgrader( $skin ); 3598 3618 $result = $upgrader->install( $api->download_link ); 3599 3619 3600 3620 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3601 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3621 $status['debug'] = $skin->get_upgrade_messages(); 3602 3622 } 3603 3623 3604 3624 if ( is_wp_error( $result ) ) { 3625 $status['errorCode'] = $result->get_error_code(); 3605 3626 $status['errorMessage'] = $result->get_error_message(); 3606 3627 wp_send_json_error( $status ); 3628 } elseif ( is_wp_error( $skin->result ) ) { 3629 $status['errorCode'] = $skin->result->get_error_code(); 3630 $status['errorMessage'] = $skin->result->get_error_message(); 3631 wp_send_json_error( $status ); 3632 } elseif ( $skin->get_errors()->get_error_code() ) { 3633 $status['errorMessage'] = $skin->get_error_messages(); 3634 wp_send_json_error( $status ); 3607 3635 } elseif ( is_null( $result ) ) { 3608 3636 global $wp_filesystem; 3609 3637 … … 3612 3640 3613 3641 // Pass through the error from WP_Filesystem if one was raised. 3614 3642 if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { 3643 $status['errorCode'] = $wp_filesystem->errors->get_error_code(); 3615 3644 $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); 3616 3645 } 3617 3646 … … 3680 3709 3681 3710 wp_update_plugins(); 3682 3711 3683 $skin = new Automatic_Upgrader_Skin();3712 $skin = new WP_Ajax_Upgrader_Skin(); 3684 3713 $upgrader = new Plugin_Upgrader( $skin ); 3685 3714 $result = $upgrader->bulk_upgrade( array( $plugin ) ); 3686 3715 3687 3716 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3688 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3717 $status['debug'] = $skin->get_upgrade_messages(); 3689 3718 } 3690 3719 3691 if ( is_array( $result ) && empty( $result[ $plugin ] ) && is_wp_error( $skin->result ) ) { 3692 $result = $skin->result; 3693 } 3694 3695 if ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) { 3720 if ( is_wp_error( $result ) ) { 3721 $status['errorCode'] = $result->get_error_code(); 3722 $status['errorMessage'] = $result->get_error_message(); 3723 wp_send_json_error( $status ); 3724 } elseif ( is_wp_error( $skin->result ) ) { 3725 $status['errorCode'] = $skin->result->get_error_code(); 3726 $status['errorMessage'] = $skin->result->get_error_message(); 3727 wp_send_json_error( $status ); 3728 } elseif ( $skin->get_errors()->get_error_code() ) { 3729 $status['errorMessage'] = $skin->get_error_messages(); 3730 wp_send_json_error( $status ); 3731 } elseif ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) { 3696 3732 $plugin_update_data = current( $result ); 3697 3733 3698 3734 /* … … 3716 3752 $status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); 3717 3753 } 3718 3754 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 3755 } elseif ( false === $result ) { 3723 3756 global $wp_filesystem; 3724 3757 -
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 * Retrieves a string for error messages 58 * 59 * @since 4.6.0 60 * @access public 61 * 62 * @return string Error messages during an upgrade. 63 */ 64 public function get_error_messages() { 65 $messages = array(); 66 67 foreach ( $this->errors->get_error_codes() as $error_code ) { 68 if ( $this->errors->get_error_data( $error_code ) && is_string( $this->errors->get_error_data( $error_code ) ) ) { 69 $messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $this->errors->get_error_data( $error_code ) ) ); 70 } else { 71 $messages[] = $this->errors->get_error_message( $error_code ); 72 } 73 } 74 75 return implode( ', ', $messages ); 76 } 77 78 /** 79 * Stores a log entry for an error. 80 * 81 * @since 4.6.0 82 * @access public 83 * 84 * @param string|WP_Error $errors 85 */ 86 public function error( $errors ) { 87 if ( is_string( $errors ) ) { 88 $string = $errors; 89 if ( ! empty( $this->upgrader->strings[ $string ] ) ) { 90 $string = $this->upgrader->strings[ $string ]; 91 } 92 93 if ( false !== strpos( $string, '%' ) ) { 94 $args = func_get_args(); 95 $args = array_splice( $args, 1 ); 96 if ( ! empty( $args ) ) { 97 $string = vsprintf( $string, $args ); 98 } 99 } 100 101 // Count existing errors to generate an unique error code. 102 $errors_count = count( $errors->get_error_codes() ); 103 $this->errors->add( 'unknown_error_' . $errors_count + 1 , $string ); 104 } elseif ( is_wp_error( $errors ) ) { 105 foreach ( $errors->get_error_codes() as $error_code ) { 106 $this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) ); 107 } 108 } 109 110 $args = func_get_args(); 111 call_user_func_array( array( $this, 'parent::error' ), $args ); 112 } 113 114 /** 115 * Stores a log entry. 116 * 117 * @since 4.6.0 118 * @access public 119 * 120 * @param string|array|WP_Error $data 121 */ 122 public function feedback( $data ) { 123 if ( is_wp_error( $data ) ) { 124 foreach ( $data->get_error_codes() as $error_code ) { 125 $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) ); 126 } 127 } 128 129 $args = func_get_args(); 130 call_user_func_array( array( $this, 'parent::feedback' ), $args ); 131 } 132 } -
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. -
src/wp-admin/js/updates.js
526 526 $card.removeClass( 'plugin-card-install-failed' ).find( '.notice.notice-error' ).remove(); 527 527 528 528 $document.trigger( 'wp-plugin-installing', args ); 529 529 530 530 return wp.updates.ajax( 'install-plugin', args ); 531 531 }; 532 532 … … 718 718 wp.a11y.speak( wp.updates.l10n.deleting, 'polite' ); 719 719 720 720 $document.trigger( 'wp-plugin-deleting', args ); 721 721 722 722 return wp.updates.ajax( 'delete-plugin', args ); 723 723 }; 724 724 … … 1043 1043 $( '.install-theme-info, [data-slug="' + args.slug + '"]' ).removeClass( 'theme-install-failed' ).find( '.notice.notice-error' ).remove(); 1044 1044 1045 1045 $document.trigger( 'wp-theme-installing', args ); 1046 1046 1047 1047 return wp.updates.ajax( 'install-theme', args ); 1048 1048 }; 1049 1049 … … 1174 1174 $( '.theme-info .update-message' ).remove(); 1175 1175 1176 1176 $document.trigger( 'wp-theme-deleting', args ); 1177 1177 1178 1178 return wp.updates.ajax( 'delete-theme', args ); 1179 1179 }; 1180 1180 … … 1525 1525 * @returns {boolean} Whether there is an error that needs to be handled or not. 1526 1526 */ 1527 1527 wp.updates.maybeHandleCredentialError = function( response, action ) { 1528 if ( response.errorCode && 'unable_to_connect_to_filesystem' === response.errorCode ) {1528 if ( wp.updates.shouldRequestFilesystemCredentials && response.errorCode && 'unable_to_connect_to_filesystem' === response.errorCode ) { 1529 1529 wp.updates.credentialError( response, action ); 1530 1530 return true; 1531 1531 } … … 1982 1982 $bulkActionForm.find( '.manage-column [type="checkbox"]' ).prop( 'checked', false ); 1983 1983 1984 1984 $document.trigger( 'wp-' + type + '-bulk-' + bulkAction, itemsSelected ); 1985 1985 1986 1986 // Find all the checkboxes which have been checked. 1987 1987 itemsSelected.each( function( index, element ) { 1988 1988 var $checkbox = $( element ),