3
* Upgrader API: WP_Ajax_Upgrader_Skin class
11
* Upgrader Skin for Ajax WordPress upgrades.
13
* This skin is designed to be used for Ajax updates.
17
* @see Automatic_Upgrader_Skin
19
class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
22
* Holds the WP_Error object.
28
protected $errors = null;
36
* @param array $args Options for the upgrader, see WP_Upgrader_Skin::__construct().
38
public function __construct( $args = array() ) {
39
parent::__construct( $args );
41
$this->errors = new WP_Error();
45
* Retrieves the list of errors.
50
* @return WP_Error Errors during an upgrade.
52
public function get_errors() {
57
* Retrieves a string for error messages.
62
* @return string Error messages during an upgrade.
64
public function get_error_messages() {
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 ) ) );
71
$messages[] = $this->errors->get_error_message( $error_code );
75
return implode( ', ', $messages );
79
* Stores a log entry for an error.
84
* @param string|WP_Error $errors Errors.
86
public function error( $errors ) {
87
if ( is_string( $errors ) ) {
89
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
90
$string = $this->upgrader->strings[ $string ];
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 );
101
// Count existing errors to generate an unique error code.
102
$errors_count = count( $errors->get_error_codes() );
103
$this->errors->add( 'unknown_upgrade_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 ) );
110
$args = func_get_args();
111
call_user_func_array( array( $this, 'parent::error' ), $args );
115
* Stores a log entry.
120
* @param string|array|WP_Error $data Log entry data.
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 ) );
129
$args = func_get_args();
130
call_user_func_array( array( $this, 'parent::feedback' ), $args );