2016-08-05 00:18:30 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Upgrader API: WP_Ajax_Upgrader_Skin class
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Upgrader
|
|
|
|
* @since 4.6.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upgrader Skin for Ajax WordPress upgrades.
|
|
|
|
*
|
|
|
|
* This skin is designed to be used for Ajax updates.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
|
|
|
*
|
|
|
|
* @see Automatic_Upgrader_Skin
|
|
|
|
*/
|
|
|
|
class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds the WP_Error object.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
|
|
|
* @var null|WP_Error
|
|
|
|
*/
|
|
|
|
protected $errors = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
|
|
|
*
|
|
|
|
* @param array $args Options for the upgrader, see WP_Upgrader_Skin::__construct().
|
|
|
|
*/
|
|
|
|
public function __construct( $args = array() ) {
|
|
|
|
parent::__construct( $args );
|
|
|
|
|
|
|
|
$this->errors = new WP_Error();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the list of errors.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
|
|
|
*
|
|
|
|
* @return WP_Error Errors during an upgrade.
|
|
|
|
*/
|
|
|
|
public function get_errors() {
|
|
|
|
return $this->errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a string for error messages.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
|
|
|
*
|
|
|
|
* @return string Error messages during an upgrade.
|
|
|
|
*/
|
|
|
|
public function get_error_messages() {
|
|
|
|
$messages = array();
|
|
|
|
|
|
|
|
foreach ( $this->errors->get_error_codes() as $error_code ) {
|
2018-02-27 03:31:31 +01:00
|
|
|
$error_data = $this->errors->get_error_data( $error_code );
|
|
|
|
|
|
|
|
if ( $error_data && is_string( $error_data ) ) {
|
|
|
|
$messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $error_data ) );
|
2016-08-05 00:18:30 +02:00
|
|
|
} else {
|
|
|
|
$messages[] = $this->errors->get_error_message( $error_code );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode( ', ', $messages );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores a log entry for an error.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
2019-10-09 06:28:02 +02:00
|
|
|
* @since 5.3.0 Formalized the existing `...$args` parameter by adding it
|
|
|
|
* to the function signature.
|
2016-08-05 00:18:30 +02:00
|
|
|
*
|
2019-09-15 12:42:54 +02:00
|
|
|
* @param string|WP_Error $errors Errors.
|
|
|
|
* @param mixed ...$args Optional text replacements.
|
2016-08-05 00:18:30 +02:00
|
|
|
*/
|
2019-09-15 12:42:54 +02:00
|
|
|
public function error( $errors, ...$args ) {
|
2016-08-05 00:18:30 +02:00
|
|
|
if ( is_string( $errors ) ) {
|
|
|
|
$string = $errors;
|
|
|
|
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
|
|
|
|
$string = $this->upgrader->strings[ $string ];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( false !== strpos( $string, '%' ) ) {
|
|
|
|
if ( ! empty( $args ) ) {
|
|
|
|
$string = vsprintf( $string, $args );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 16:14:52 +02:00
|
|
|
// Count existing errors to generate a unique error code.
|
2017-07-26 15:39:44 +02:00
|
|
|
$errors_count = count( $this->errors->get_error_codes() );
|
2019-05-31 16:14:52 +02:00
|
|
|
$this->errors->add( 'unknown_upgrade_error_' . ( $errors_count + 1 ), $string );
|
2016-08-05 00:18:30 +02:00
|
|
|
} elseif ( is_wp_error( $errors ) ) {
|
|
|
|
foreach ( $errors->get_error_codes() as $error_code ) {
|
|
|
|
$this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-15 12:42:54 +02:00
|
|
|
parent::error( $errors, ...$args );
|
2016-08-05 00:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores a log entry.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
2019-10-09 06:28:02 +02:00
|
|
|
* @since 5.3.0 Formalized the existing `...$args` parameter by adding it
|
|
|
|
* to the function signature.
|
2016-08-05 00:18:30 +02:00
|
|
|
*
|
2019-09-15 12:42:54 +02:00
|
|
|
* @param string|array|WP_Error $data Log entry data.
|
|
|
|
* @param mixed ...$args Optional text replacements.
|
2016-08-05 00:18:30 +02:00
|
|
|
*/
|
2019-09-15 12:42:54 +02:00
|
|
|
public function feedback( $data, ...$args ) {
|
2016-08-05 00:18:30 +02:00
|
|
|
if ( is_wp_error( $data ) ) {
|
|
|
|
foreach ( $data->get_error_codes() as $error_code ) {
|
|
|
|
$this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-15 12:42:54 +02:00
|
|
|
parent::feedback( $data, ...$args );
|
2016-08-05 00:18:30 +02:00
|
|
|
}
|
|
|
|
}
|