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: 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 16:36:26 +02:00
if ( str_contains ( $feedback , '%' ) ) {
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 () {
2023-05-18 13:37:27 +02:00
// Nothing. This will be displayed within an iframe.
2016-05-10 13:11:30 +02:00
}
/**
*/
public function footer () {
2023-05-18 13:37:27 +02:00
// Nothing. This will be displayed within an iframe.
2016-05-10 13:11:30 +02:00
}
/**
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>' ;
2023-06-26 00:57:26 +02:00
// This progress messages div gets moved via JavaScript when clicking on "More 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 ) {
Administration: Use `wp_admin_notice()` more in `/wp-admin/includes/`.
Adds further usages of `wp_admin_notice()` in `/wp-admin/includes/` on `.notice-error`, `.notice-warning`, `.error`, and `.updated`.
Ongoing task to implement new function across core.
Follow-up to [56408], [56409], [56410], [56518], [56570], [56571], [56572], [56573], [56576], [56589], [56590], [56597].
Props joedolson, mukesh27, costdev.
See #57791.
Built from https://develop.svn.wordpress.org/trunk@56599
git-svn-id: http://core.svn.wordpress.org/trunk@56111 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-09-17 17:23:22 +02:00
$after_error_message = sprintf ( $this -> upgrader -> strings [ 'skin_update_failed_error' ], $title , '<strong>' . $this -> error . '</strong>' );
2016-05-10 13:11:30 +02:00
} else {
Administration: Use `wp_admin_notice()` more in `/wp-admin/includes/`.
Adds further usages of `wp_admin_notice()` in `/wp-admin/includes/` on `.notice-error`, `.notice-warning`, `.error`, and `.updated`.
Ongoing task to implement new function across core.
Follow-up to [56408], [56409], [56410], [56518], [56570], [56571], [56572], [56573], [56576], [56589], [56590], [56597].
Props joedolson, mukesh27, costdev.
See #57791.
Built from https://develop.svn.wordpress.org/trunk@56599
git-svn-id: http://core.svn.wordpress.org/trunk@56111 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-09-17 17:23:22 +02:00
$after_error_message = sprintf ( $this -> upgrader -> strings [ 'skin_update_failed' ], $title );
2016-05-10 13:11:30 +02:00
}
Administration: Use `wp_admin_notice()` more in `/wp-admin/includes/`.
Adds further usages of `wp_admin_notice()` in `/wp-admin/includes/` on `.notice-error`, `.notice-warning`, `.error`, and `.updated`.
Ongoing task to implement new function across core.
Follow-up to [56408], [56409], [56410], [56518], [56570], [56571], [56572], [56573], [56576], [56589], [56590], [56597].
Props joedolson, mukesh27, costdev.
See #57791.
Built from https://develop.svn.wordpress.org/trunk@56599
git-svn-id: http://core.svn.wordpress.org/trunk@56111 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-09-17 17:23:22 +02:00
wp_admin_notice (
$after_error_message ,
array (
'additional_classes' => array ( 'error' ),
)
);
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 ) .
2023-06-26 00:57:26 +02:00
' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __ ( 'More details.' ) . '<span class="dashicons dashicons-arrow-down" aria-hidden="true"></span></button>' .
2017-05-12 01:50:41 +02:00
'</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 ();
}
}