11 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. |
11 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. |
12 * |
12 * |
13 * @since 2.8.0 |
13 * @since 2.8.0 |
14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. |
14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php. |
15 */ |
15 */ |
|
16 #[AllowDynamicProperties] |
16 class WP_Upgrader_Skin { |
17 class WP_Upgrader_Skin { |
17 |
18 |
18 /** |
19 /** |
19 * Holds the upgrader data. |
20 * Holds the upgrader data. |
20 * |
21 * |
21 * @since 2.8.0 |
22 * @since 2.8.0 |
22 * |
|
23 * @var WP_Upgrader |
23 * @var WP_Upgrader |
24 */ |
24 */ |
25 public $upgrader; |
25 public $upgrader; |
26 |
26 |
27 /** |
27 /** |
28 * Whether header is done. |
28 * Whether header is done. |
29 * |
29 * |
30 * @since 2.8.0 |
30 * @since 2.8.0 |
31 * |
|
32 * @var bool |
31 * @var bool |
33 */ |
32 */ |
34 public $done_header = false; |
33 public $done_header = false; |
35 |
34 |
36 /** |
35 /** |
37 * Whether footer is done. |
36 * Whether footer is done. |
38 * |
37 * |
39 * @since 2.8.0 |
38 * @since 2.8.0 |
40 * |
|
41 * @var bool |
39 * @var bool |
42 */ |
40 */ |
43 public $done_footer = false; |
41 public $done_footer = false; |
44 |
42 |
45 /** |
43 /** |
46 * Holds the result of an upgrade. |
44 * Holds the result of an upgrade. |
47 * |
45 * |
48 * @since 2.8.0 |
46 * @since 2.8.0 |
49 * |
|
50 * @var string|bool|WP_Error |
47 * @var string|bool|WP_Error |
51 */ |
48 */ |
52 public $result = false; |
49 public $result = false; |
53 |
50 |
54 /** |
51 /** |
55 * Holds the options of an upgrade. |
52 * Holds the options of an upgrade. |
56 * |
53 * |
57 * @since 2.8.0 |
54 * @since 2.8.0 |
58 * |
|
59 * @var array |
55 * @var array |
60 */ |
56 */ |
61 public $options = array(); |
57 public $options = array(); |
62 |
58 |
63 /** |
59 /** |
138 |
138 |
139 return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership ); |
139 return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership ); |
140 } |
140 } |
141 |
141 |
142 /** |
142 /** |
|
143 * Displays the header before the update process. |
|
144 * |
143 * @since 2.8.0 |
145 * @since 2.8.0 |
144 */ |
146 */ |
145 public function header() { |
147 public function header() { |
146 if ( $this->done_header ) { |
148 if ( $this->done_header ) { |
147 return; |
149 return; |
194 public function feedback( $feedback, ...$args ) { |
202 public function feedback( $feedback, ...$args ) { |
195 if ( isset( $this->upgrader->strings[ $feedback ] ) ) { |
203 if ( isset( $this->upgrader->strings[ $feedback ] ) ) { |
196 $feedback = $this->upgrader->strings[ $feedback ]; |
204 $feedback = $this->upgrader->strings[ $feedback ]; |
197 } |
205 } |
198 |
206 |
199 if ( strpos( $feedback, '%' ) !== false ) { |
207 if ( str_contains( $feedback, '%' ) ) { |
200 if ( $args ) { |
208 if ( $args ) { |
201 $args = array_map( 'strip_tags', $args ); |
209 $args = array_map( 'strip_tags', $args ); |
202 $args = array_map( 'esc_html', $args ); |
210 $args = array_map( 'esc_html', $args ); |
203 $feedback = vsprintf( $feedback, $args ); |
211 $feedback = vsprintf( $feedback, $args ); |
204 } |
212 } |
208 } |
216 } |
209 show_message( $feedback ); |
217 show_message( $feedback ); |
210 } |
218 } |
211 |
219 |
212 /** |
220 /** |
213 * Action to perform before an update. |
221 * Performs an action before an update. |
214 * |
222 * |
215 * @since 2.8.0 |
223 * @since 2.8.0 |
216 */ |
224 */ |
217 public function before() {} |
225 public function before() {} |
218 |
226 |
219 /** |
227 /** |
220 * Action to perform following an update. |
228 * Performs an action following an update. |
221 * |
229 * |
222 * @since 2.8.0 |
230 * @since 2.8.0 |
223 */ |
231 */ |
224 public function after() {} |
232 public function after() {} |
225 |
233 |
226 /** |
234 /** |
227 * Output JavaScript that calls function to decrement the update counts. |
235 * Outputs JavaScript that calls function to decrement the update counts. |
228 * |
236 * |
229 * @since 3.9.0 |
237 * @since 3.9.0 |
230 * |
238 * |
231 * @param string $type Type of update count to decrement. Likely values include 'plugin', |
239 * @param string $type Type of update count to decrement. Likely values include 'plugin', |
232 * 'theme', 'translation', etc. |
240 * 'theme', 'translation', etc. |
237 } |
245 } |
238 |
246 |
239 if ( defined( 'IFRAME_REQUEST' ) ) { |
247 if ( defined( 'IFRAME_REQUEST' ) ) { |
240 echo '<script type="text/javascript"> |
248 echo '<script type="text/javascript"> |
241 if ( window.postMessage && JSON ) { |
249 if ( window.postMessage && JSON ) { |
242 window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname ); |
250 window.parent.postMessage( |
|
251 JSON.stringify( { |
|
252 action: "decrementUpdateCount", |
|
253 upgradeType: "' . $type . '" |
|
254 } ), |
|
255 window.location.protocol + "//" + window.location.hostname |
|
256 + ( "" !== window.location.port ? ":" + window.location.port : "" ) |
|
257 ); |
243 } |
258 } |
244 </script>'; |
259 </script>'; |
245 } else { |
260 } else { |
246 echo '<script type="text/javascript"> |
261 echo '<script type="text/javascript"> |
247 (function( wp ) { |
262 (function( wp ) { |
252 </script>'; |
267 </script>'; |
253 } |
268 } |
254 } |
269 } |
255 |
270 |
256 /** |
271 /** |
|
272 * Displays the header before the bulk update process. |
|
273 * |
257 * @since 3.0.0 |
274 * @since 3.0.0 |
258 */ |
275 */ |
259 public function bulk_header() {} |
276 public function bulk_header() {} |
260 |
277 |
261 /** |
278 /** |
|
279 * Displays the footer following the bulk update process. |
|
280 * |
262 * @since 3.0.0 |
281 * @since 3.0.0 |
263 */ |
282 */ |
264 public function bulk_footer() {} |
283 public function bulk_footer() {} |
265 |
284 |
266 /** |
285 /** |
267 * Hides the `process_failed` error message when updating by uploading a zip file. |
286 * Hides the `process_failed` error message when updating by uploading a zip file. |
268 * |
287 * |
269 * @since 5.5.0 |
288 * @since 5.5.0 |
270 * |
289 * |
271 * @param WP_Error $wp_error WP_Error object. |
290 * @param WP_Error $wp_error WP_Error object. |
272 * @return bool |
291 * @return bool True if the error should be hidden, false otherwise. |
273 */ |
292 */ |
274 public function hide_process_failed( $wp_error ) { |
293 public function hide_process_failed( $wp_error ) { |
275 return false; |
294 return false; |
276 } |
295 } |
277 } |
296 } |