Ticket #37531: 37531.patch
File 37531.patch, 5.7 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
3594 3594 3595 3595 $status['pluginName'] = $api->name; 3596 3596 3597 $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); 3597 $skin = new WP_Ajax_Upgrader_Skin(); 3598 $upgrader = new Plugin_Upgrader( ); 3598 3599 $result = $upgrader->install( $api->download_link ); 3599 3600 3600 3601 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { … … 3604 3605 if ( is_wp_error( $result ) ) { 3605 3606 $status['errorMessage'] = $result->get_error_message(); 3606 3607 wp_send_json_error( $status ); 3608 } elseif ( is_wp_error( $skin->result ) ) { 3609 $status['errorMessage'] = $skin->result->get_error_message(); 3610 wp_send_json_error( $status ); 3611 } elseif ( $skin->get_errors()->get_error_code() ) { 3612 $errors = $skin->get_errors(); 3613 3614 $messages = array(); 3615 foreach ( $errors->get_error_codes() as $error_code ) { 3616 if ( $errors->get_error_data( $error_code ) && is_string( $errors->get_error_data( $error_code ) ) ) { 3617 $messages[] = $errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $errors->get_error_data( $error_code ) ) ); 3618 } else { 3619 $messages[] = $errors->get_error_message( $error_code ); 3620 } 3621 } 3622 3623 $status['errorMessage'] = implode( ', ', $messages ); 3624 wp_send_json_error( $status ); 3607 3625 } elseif ( is_null( $result ) ) { 3608 3626 global $wp_filesystem; 3609 3627 … … 3612 3630 3613 3631 // Pass through the error from WP_Filesystem if one was raised. 3614 3632 if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { 3633 $status['errorCode'] = $wp_filesystem->errors->get_error_code(); 3615 3634 $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); 3616 3635 } 3617 3636 -
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 call_user_func_array( 'parent::error', func_get_args() ); 89 } 90 91 /** 92 * Stores a log entry. 93 * 94 * @since 4.6.0 95 * @access public 96 * 97 * @param string|array|WP_Error $data 98 */ 99 public function feedback( $data ) { 100 if ( is_wp_error( $data ) ) { 101 foreach ( $data->get_error_codes() as $error_code ) { 102 $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) ); 103 } 104 } 105 106 call_user_func_array( 'parent::feedback', func_get_args() ); 107 } 108 } -
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.