2016-05-10 13:11:30 +02:00
< ? php
/**
2016-05-10 13:31:28 +02:00
* Upgrader API : Bulk_Upgrader_Skin class
2016-05-10 13:11:30 +02:00
*
* @ package WordPress
* @ subpackage Upgrader
2016-05-10 13:31:28 +02:00
* @ since 4.6 . 0
2016-05-10 13:11:30 +02:00
*/
/**
2016-05-10 13:31:28 +02:00
* Generic Bulk Upgrader Skin for WordPress Upgrades .
2016-05-10 13:11:30 +02:00
*
* @ since 3.0 . 0
2016-05-13 22:59:27 +02:00
* @ since 4.6 . 0 Moved to its own file from wp - admin / includes / class - wp - upgrader - skins . php .
2016-07-09 15:45:33 +02:00
*
* @ see WP_Upgrader_Skin
2016-05-10 13:11:30 +02:00
*/
class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
public $in_loop = false ;
/**
* @ var string | false
*/
public $error = false ;
/**
* @ param array $args
*/
2017-12-01 00:11:00 +01:00
public function __construct ( $args = array () ) {
$defaults = array (
'url' => '' ,
'nonce' => '' ,
);
$args = wp_parse_args ( $args , $defaults );
parent :: __construct ( $args );
2016-05-10 13:11:30 +02:00
}
/**
*/
public function add_strings () {
2017-12-01 00:11:00 +01:00
$this -> upgrader -> strings [ 'skin_upgrade_start' ] = __ ( 'The update process is starting. This process may take a while on some hosts, so please be patient.' );
2019-09-03 02:41:05 +02:00
/* translators: 1: Title of an update, 2: Error message. */
2017-12-01 00:11:00 +01:00
$this -> upgrader -> strings [ 'skin_update_failed_error' ] = __ ( 'An error occurred while updating %1$s: %2$s' );
2019-09-03 02:41:05 +02:00
/* translators: %s: Title of an update. */
2018-03-11 17:44:34 +01:00
$this -> upgrader -> strings [ 'skin_update_failed' ] = __ ( 'The update of %s failed.' );
2019-09-03 02:41:05 +02:00
/* translators: %s: Title of an update. */
2018-03-11 17:44:34 +01:00
$this -> upgrader -> strings [ 'skin_update_successful' ] = __ ( '%s updated successfully.' );
2017-12-01 00:11:00 +01:00
$this -> upgrader -> strings [ 'skin_upgrade_end' ] = __ ( 'All updates have been completed.' );
2016-05-10 13:11:30 +02:00
}
/**
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `WP_Upgrader_Skin::feedback()`.
In the parent class, renames the parameter `$string` to `$feedback`.
Why? `string` is a PHP reserved keyword.
In each child class: renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
Follow-up to [11005], [25228], [30680], [32655], [38199], [49596].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51781
git-svn-id: http://core.svn.wordpress.org/trunk@51388 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 15:48:56 +02:00
* @ since 5.9 . 0 Renamed `$string` ( a PHP reserved keyword ) to `$feedback` for PHP 8 named parameter support .
*
* @ param string $feedback Message data .
* @ param mixed ... $args Optional text replacements .
2016-05-10 13:11:30 +02:00
*/
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `WP_Upgrader_Skin::feedback()`.
In the parent class, renames the parameter `$string` to `$feedback`.
Why? `string` is a PHP reserved keyword.
In each child class: renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
Follow-up to [11005], [25228], [30680], [32655], [38199], [49596].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51781
git-svn-id: http://core.svn.wordpress.org/trunk@51388 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 15:48:56 +02:00
public function feedback ( $feedback , ... $args ) {
if ( isset ( $this -> upgrader -> strings [ $feedback ] ) ) {
$feedback = $this -> upgrader -> strings [ $feedback ];
2017-12-01 00:11:00 +01:00
}
2016-05-10 13:11:30 +02:00
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `WP_Upgrader_Skin::feedback()`.
In the parent class, renames the parameter `$string` to `$feedback`.
Why? `string` is a PHP reserved keyword.
In each child class: renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
Follow-up to [11005], [25228], [30680], [32655], [38199], [49596].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51781
git-svn-id: http://core.svn.wordpress.org/trunk@51388 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 15:48:56 +02:00
if ( strpos ( $feedback , '%' ) !== false ) {
2016-05-10 13:11:30 +02:00
if ( $args ) {
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `WP_Upgrader_Skin::feedback()`.
In the parent class, renames the parameter `$string` to `$feedback`.
Why? `string` is a PHP reserved keyword.
In each child class: renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
Follow-up to [11005], [25228], [30680], [32655], [38199], [49596].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51781
git-svn-id: http://core.svn.wordpress.org/trunk@51388 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 15:48:56 +02:00
$args = array_map ( 'strip_tags' , $args );
$args = array_map ( 'esc_html' , $args );
$feedback = vsprintf ( $feedback , $args );
2016-05-10 13:11:30 +02:00
}
}
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `WP_Upgrader_Skin::feedback()`.
In the parent class, renames the parameter `$string` to `$feedback`.
Why? `string` is a PHP reserved keyword.
In each child class: renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
Follow-up to [11005], [25228], [30680], [32655], [38199], [49596].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51781
git-svn-id: http://core.svn.wordpress.org/trunk@51388 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 15:48:56 +02:00
if ( empty ( $feedback ) ) {
2016-05-10 13:11:30 +02:00
return ;
2017-12-01 00:11:00 +01:00
}
if ( $this -> in_loop ) {
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `WP_Upgrader_Skin::feedback()`.
In the parent class, renames the parameter `$string` to `$feedback`.
Why? `string` is a PHP reserved keyword.
In each child class: renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
Follow-up to [11005], [25228], [30680], [32655], [38199], [49596].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51781
git-svn-id: http://core.svn.wordpress.org/trunk@51388 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 15:48:56 +02:00
echo " $feedback <br /> \n " ;
2017-12-01 00:11:00 +01:00
} else {
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `WP_Upgrader_Skin::feedback()`.
In the parent class, renames the parameter `$string` to `$feedback`.
Why? `string` is a PHP reserved keyword.
In each child class: renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
Follow-up to [11005], [25228], [30680], [32655], [38199], [49596].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51781
git-svn-id: http://core.svn.wordpress.org/trunk@51388 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 15:48:56 +02:00
echo " <p> $feedback </p> \n " ;
2017-12-01 00:11:00 +01:00
}
2016-05-10 13:11:30 +02:00
}
/**
*/
public function header () {
// Nothing, This will be displayed within a iframe.
}
/**
*/
public function footer () {
// Nothing, This will be displayed within a iframe.
}
/**
2021-09-09 15:59:56 +02:00
* @ since 5.9 . 0 Renamed `$error` to `$errors` for PHP 8 named parameter support .
*
* @ param string | WP_Error $errors Errors .
2016-05-10 13:11:30 +02:00
*/
2021-09-09 15:59:56 +02:00
public function error ( $errors ) {
if ( is_string ( $errors ) && isset ( $this -> upgrader -> strings [ $errors ] ) ) {
$this -> error = $this -> upgrader -> strings [ $errors ];
2017-12-01 00:11:00 +01:00
}
2016-05-10 13:11:30 +02:00
2021-09-09 15:59:56 +02:00
if ( is_wp_error ( $errors ) ) {
2016-05-10 13:11:30 +02:00
$messages = array ();
2021-09-09 15:59:56 +02:00
foreach ( $errors -> get_error_messages () as $emessage ) {
if ( $errors -> get_error_data () && is_string ( $errors -> get_error_data () ) ) {
$messages [] = $emessage . ' ' . esc_html ( strip_tags ( $errors -> get_error_data () ) );
2017-12-01 00:11:00 +01:00
} else {
2016-05-10 13:11:30 +02:00
$messages [] = $emessage ;
2017-12-01 00:11:00 +01:00
}
2016-05-10 13:11:30 +02:00
}
2017-12-01 00:11:00 +01:00
$this -> error = implode ( ', ' , $messages );
2016-05-10 13:11:30 +02:00
}
2017-12-01 00:11:00 +01:00
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').hide();</script>' ;
2016-05-10 13:11:30 +02:00
}
/**
*/
public function bulk_header () {
2017-12-01 00:11:00 +01:00
$this -> feedback ( 'skin_upgrade_start' );
2016-05-10 13:11:30 +02:00
}
/**
*/
public function bulk_footer () {
2017-12-01 00:11:00 +01:00
$this -> feedback ( 'skin_upgrade_end' );
2016-05-10 13:11:30 +02:00
}
/**
* @ param string $title
*/
2017-12-01 00:11:00 +01:00
public function before ( $title = '' ) {
2016-05-10 13:11:30 +02:00
$this -> in_loop = true ;
printf ( '<h2>' . $this -> upgrader -> strings [ 'skin_before_update_header' ] . ' <span class="spinner waiting-' . $this -> upgrader -> update_current . '"></span></h2>' , $title , $this -> upgrader -> update_current , $this -> upgrader -> update_count );
2017-12-01 00:11:00 +01:00
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').css("display", "inline-block");</script>' ;
2017-05-12 01:50:41 +02:00
// This progress messages div gets moved via JavaScript when clicking on "Show details.".
2017-12-01 00:11:00 +01:00
echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr ( $this -> upgrader -> update_current ) . '"><p>' ;
2016-05-10 13:11:30 +02:00
$this -> flush_output ();
}
/**
* @ param string $title
*/
2017-12-01 00:11:00 +01:00
public function after ( $title = '' ) {
2016-05-10 13:11:30 +02:00
echo '</p></div>' ;
if ( $this -> error || ! $this -> result ) {
if ( $this -> error ) {
2017-12-01 00:11:00 +01:00
echo '<div class="error"><p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_failed_error' ], $title , '<strong>' . $this -> error . '</strong>' ) . '</p></div>' ;
2016-05-10 13:11:30 +02:00
} else {
2017-12-01 00:11:00 +01:00
echo '<div class="error"><p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_failed' ], $title ) . '</p></div>' ;
2016-05-10 13:11:30 +02:00
}
2017-12-01 00:11:00 +01:00
echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js ( $this -> upgrader -> update_current ) . '\').show();</script>' ;
2016-05-10 13:11:30 +02:00
}
if ( $this -> result && ! is_wp_error ( $this -> result ) ) {
2017-05-12 01:50:41 +02:00
if ( ! $this -> error ) {
echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr ( $this -> upgrader -> update_current ) . '">' .
'<p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_successful' ], $title ) .
' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __ ( 'Show details.' ) . '</button>' .
'</p></div>' ;
}
2017-12-01 00:11:00 +01:00
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').hide();</script>' ;
2016-05-10 13:11:30 +02:00
}
$this -> reset ();
$this -> flush_output ();
}
/**
*/
public function reset () {
$this -> in_loop = false ;
2017-12-01 00:11:00 +01:00
$this -> error = false ;
2016-05-10 13:11:30 +02:00
}
/**
*/
public function flush_output () {
wp_ob_end_flush_all ();
flush ();
}
}