20 |
20 |
21 /** |
21 /** |
22 * Holds the WP_Error object. |
22 * Holds the WP_Error object. |
23 * |
23 * |
24 * @since 4.6.0 |
24 * @since 4.6.0 |
|
25 * |
25 * @var null|WP_Error |
26 * @var null|WP_Error |
26 */ |
27 */ |
27 protected $errors = null; |
28 protected $errors = null; |
28 |
29 |
29 /** |
30 /** |
30 * Constructor. |
31 * Constructor. |
31 * |
32 * |
|
33 * Sets up the WordPress Ajax upgrader skin. |
|
34 * |
32 * @since 4.6.0 |
35 * @since 4.6.0 |
33 * |
36 * |
34 * @param array $args Options for the upgrader, see WP_Upgrader_Skin::__construct(). |
37 * @see WP_Upgrader_Skin::__construct() |
|
38 * |
|
39 * @param array $args Optional. The WordPress Ajax upgrader skin arguments to |
|
40 * override default options. See WP_Upgrader_Skin::__construct(). |
|
41 * Default empty array. |
35 */ |
42 */ |
36 public function __construct( $args = array() ) { |
43 public function __construct( $args = array() ) { |
37 parent::__construct( $args ); |
44 parent::__construct( $args ); |
38 |
45 |
39 $this->errors = new WP_Error(); |
46 $this->errors = new WP_Error(); |
75 |
82 |
76 /** |
83 /** |
77 * Stores a log entry for an error. |
84 * Stores a log entry for an error. |
78 * |
85 * |
79 * @since 4.6.0 |
86 * @since 4.6.0 |
|
87 * @since 5.3.0 Formalized the existing `...$args` parameter by adding it |
|
88 * to the function signature. |
80 * |
89 * |
81 * @param string|WP_Error $errors Errors. |
90 * @param string|WP_Error $errors Errors. |
|
91 * @param mixed ...$args Optional text replacements. |
82 */ |
92 */ |
83 public function error( $errors ) { |
93 public function error( $errors, ...$args ) { |
84 if ( is_string( $errors ) ) { |
94 if ( is_string( $errors ) ) { |
85 $string = $errors; |
95 $string = $errors; |
86 if ( ! empty( $this->upgrader->strings[ $string ] ) ) { |
96 if ( ! empty( $this->upgrader->strings[ $string ] ) ) { |
87 $string = $this->upgrader->strings[ $string ]; |
97 $string = $this->upgrader->strings[ $string ]; |
88 } |
98 } |
89 |
99 |
90 if ( false !== strpos( $string, '%' ) ) { |
100 if ( false !== strpos( $string, '%' ) ) { |
91 $args = func_get_args(); |
|
92 $args = array_splice( $args, 1 ); |
|
93 if ( ! empty( $args ) ) { |
101 if ( ! empty( $args ) ) { |
94 $string = vsprintf( $string, $args ); |
102 $string = vsprintf( $string, $args ); |
95 } |
103 } |
96 } |
104 } |
97 |
105 |
98 // Count existing errors to generate an unique error code. |
106 // Count existing errors to generate a unique error code. |
99 $errors_count = count( $this->errors->get_error_codes() ); |
107 $errors_count = count( $this->errors->get_error_codes() ); |
100 $this->errors->add( 'unknown_upgrade_error_' . $errors_count + 1, $string ); |
108 $this->errors->add( 'unknown_upgrade_error_' . ( $errors_count + 1 ), $string ); |
101 } elseif ( is_wp_error( $errors ) ) { |
109 } elseif ( is_wp_error( $errors ) ) { |
102 foreach ( $errors->get_error_codes() as $error_code ) { |
110 foreach ( $errors->get_error_codes() as $error_code ) { |
103 $this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) ); |
111 $this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) ); |
104 } |
112 } |
105 } |
113 } |
106 |
114 |
107 $args = func_get_args(); |
115 parent::error( $errors, ...$args ); |
108 call_user_func_array( array( $this, 'parent::error' ), $args ); |
|
109 } |
116 } |
110 |
117 |
111 /** |
118 /** |
112 * Stores a log entry. |
119 * Stores a log entry. |
113 * |
120 * |
114 * @since 4.6.0 |
121 * @since 4.6.0 |
|
122 * @since 5.3.0 Formalized the existing `...$args` parameter by adding it |
|
123 * to the function signature. |
115 * |
124 * |
116 * @param string|array|WP_Error $data Log entry data. |
125 * @param string|array|WP_Error $data Log entry data. |
|
126 * @param mixed ...$args Optional text replacements. |
117 */ |
127 */ |
118 public function feedback( $data ) { |
128 public function feedback( $data, ...$args ) { |
119 if ( is_wp_error( $data ) ) { |
129 if ( is_wp_error( $data ) ) { |
120 foreach ( $data->get_error_codes() as $error_code ) { |
130 foreach ( $data->get_error_codes() as $error_code ) { |
121 $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) ); |
131 $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) ); |
122 } |
132 } |
123 } |
133 } |
124 |
134 |
125 $args = func_get_args(); |
135 parent::feedback( $data, ...$args ); |
126 call_user_func_array( array( $this, 'parent::feedback' ), $args ); |
|
127 } |
136 } |
128 } |
137 } |