2016-05-10 07:11:30 -04:00
< ? php
/**
2016-05-10 07:31:28 -04:00
* Upgrader API : Bulk_Upgrader_Skin class
2016-05-10 07:11:30 -04:00
*
* @ package WordPress
* @ subpackage Upgrader
2016-05-10 07:31:28 -04:00
* @ since 4.6 . 0
2016-05-10 07:11:30 -04:00
*/
/**
2016-05-10 07:31:28 -04:00
* Generic Bulk Upgrader Skin for WordPress Upgrades .
2016-05-10 07:11:30 -04:00
*
* @ since 3.0 . 0
2016-05-13 16:59:27 -04:00
* @ since 4.6 . 0 Moved to its own file from wp - admin / includes / class - wp - upgrader - skins . php .
2016-07-09 09:45:33 -04:00
*
* @ see WP_Upgrader_Skin
2016-05-10 07:11:30 -04:00
*/
class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
public $in_loop = false ;
/**
* @ var string | false
*/
public $error = false ;
/**
* @ param array $args
*/
2017-11-30 18:11:00 -05:00
public function __construct ( $args = array () ) {
$defaults = array (
'url' => '' ,
'nonce' => '' ,
);
$args = wp_parse_args ( $args , $defaults );
parent :: __construct ( $args );
2016-05-10 07:11:30 -04:00
}
/**
*/
public function add_strings () {
2017-11-30 18:11:00 -05: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-02 20:41:05 -04:00
/* translators: 1: Title of an update, 2: Error message. */
2017-11-30 18:11:00 -05:00
$this -> upgrader -> strings [ 'skin_update_failed_error' ] = __ ( 'An error occurred while updating %1$s: %2$s' );
2019-09-02 20:41:05 -04:00
/* translators: %s: Title of an update. */
2018-03-11 12:44:34 -04:00
$this -> upgrader -> strings [ 'skin_update_failed' ] = __ ( 'The update of %s failed.' );
2019-09-02 20:41:05 -04:00
/* translators: %s: Title of an update. */
2018-03-11 12:44:34 -04:00
$this -> upgrader -> strings [ 'skin_update_successful' ] = __ ( '%s updated successfully.' );
2017-11-30 18:11:00 -05:00
$this -> upgrader -> strings [ 'skin_upgrade_end' ] = __ ( 'All updates have been completed.' );
2016-05-10 07:11:30 -04: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 09:48:56 -04: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 07:11:30 -04: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 09:48:56 -04:00
public function feedback ( $feedback , ... $args ) {
if ( isset ( $this -> upgrader -> strings [ $feedback ] ) ) {
$feedback = $this -> upgrader -> strings [ $feedback ];
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:11:30 -04:00
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 10:36:26 -04:00
if ( str_contains ( $feedback , '%' ) ) {
2016-05-10 07:11:30 -04: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 09:48:56 -04:00
$args = array_map ( 'strip_tags' , $args );
$args = array_map ( 'esc_html' , $args );
$feedback = vsprintf ( $feedback , $args );
2016-05-10 07:11:30 -04: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 09:48:56 -04:00
if ( empty ( $feedback ) ) {
2016-05-10 07:11:30 -04:00
return ;
2017-11-30 18:11:00 -05: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 09:48:56 -04:00
echo " $feedback <br /> \n " ;
2017-11-30 18:11:00 -05: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 09:48:56 -04:00
echo " <p> $feedback </p> \n " ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:11:30 -04:00
}
/**
*/
public function header () {
2023-05-18 07:37:27 -04:00
// Nothing. This will be displayed within an iframe.
2016-05-10 07:11:30 -04:00
}
/**
*/
public function footer () {
2023-05-18 07:37:27 -04:00
// Nothing. This will be displayed within an iframe.
2016-05-10 07:11:30 -04:00
}
/**
2021-09-09 09:59:56 -04:00
* @ since 5.9 . 0 Renamed `$error` to `$errors` for PHP 8 named parameter support .
*
* @ param string | WP_Error $errors Errors .
2016-05-10 07:11:30 -04:00
*/
2021-09-09 09:59:56 -04:00
public function error ( $errors ) {
if ( is_string ( $errors ) && isset ( $this -> upgrader -> strings [ $errors ] ) ) {
$this -> error = $this -> upgrader -> strings [ $errors ];
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:11:30 -04:00
2021-09-09 09:59:56 -04:00
if ( is_wp_error ( $errors ) ) {
2016-05-10 07:11:30 -04:00
$messages = array ();
2021-09-09 09:59:56 -04: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-11-30 18:11:00 -05:00
} else {
2016-05-10 07:11:30 -04:00
$messages [] = $emessage ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:11:30 -04:00
}
2017-11-30 18:11:00 -05:00
$this -> error = implode ( ', ' , $messages );
2016-05-10 07:11:30 -04:00
}
2017-11-30 18:11:00 -05:00
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').hide();</script>' ;
2016-05-10 07:11:30 -04:00
}
/**
*/
public function bulk_header () {
2017-11-30 18:11:00 -05:00
$this -> feedback ( 'skin_upgrade_start' );
2016-05-10 07:11:30 -04:00
}
/**
*/
public function bulk_footer () {
2017-11-30 18:11:00 -05:00
$this -> feedback ( 'skin_upgrade_end' );
2016-05-10 07:11:30 -04:00
}
/**
* @ param string $title
*/
2017-11-30 18:11:00 -05:00
public function before ( $title = '' ) {
2016-05-10 07:11:30 -04: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-11-30 18:11:00 -05:00
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').css("display", "inline-block");</script>' ;
2017-05-11 19:50:41 -04:00
// This progress messages div gets moved via JavaScript when clicking on "Show details.".
2017-11-30 18:11:00 -05:00
echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr ( $this -> upgrader -> update_current ) . '"><p>' ;
2016-05-10 07:11:30 -04:00
$this -> flush_output ();
}
/**
* @ param string $title
*/
2017-11-30 18:11:00 -05:00
public function after ( $title = '' ) {
2016-05-10 07:11:30 -04:00
echo '</p></div>' ;
if ( $this -> error || ! $this -> result ) {
if ( $this -> error ) {
2017-11-30 18:11:00 -05:00
echo '<div class="error"><p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_failed_error' ], $title , '<strong>' . $this -> error . '</strong>' ) . '</p></div>' ;
2016-05-10 07:11:30 -04:00
} else {
2017-11-30 18:11:00 -05:00
echo '<div class="error"><p>' . sprintf ( $this -> upgrader -> strings [ 'skin_update_failed' ], $title ) . '</p></div>' ;
2016-05-10 07:11:30 -04:00
}
2017-11-30 18:11:00 -05:00
echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js ( $this -> upgrader -> update_current ) . '\').show();</script>' ;
2016-05-10 07:11:30 -04:00
}
if ( $this -> result && ! is_wp_error ( $this -> result ) ) {
2017-05-11 19:50:41 -04: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-11-30 18:11:00 -05:00
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js ( $this -> upgrader -> update_current ) . '\').hide();</script>' ;
2016-05-10 07:11:30 -04:00
}
$this -> reset ();
$this -> flush_output ();
}
/**
*/
public function reset () {
$this -> in_loop = false ;
2017-11-30 18:11:00 -05:00
$this -> error = false ;
2016-05-10 07:11:30 -04:00
}
/**
*/
public function flush_output () {
wp_ob_end_flush_all ();
flush ();
}
}