2016-08-05 00:18:30 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Upgrader API: WP_Ajax_Upgrader_Skin class
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Upgrader
|
|
|
|
* @since 4.6.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upgrader Skin for Ajax WordPress upgrades.
|
|
|
|
*
|
|
|
|
* This skin is designed to be used for Ajax updates.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
|
|
|
*
|
|
|
|
* @see Automatic_Upgrader_Skin
|
|
|
|
*/
|
|
|
|
class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
|
|
|
|
|
Code Modernization: Explicitly declare all properties in `WP_Ajax_Upgrader_Skin`.
Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.
In this case, the `$plugin_info` and `$theme_info` properties are set in `Plugin_Upgrader::bulk_upgrade()` and `Theme_Upgrader::bulk_upgrade()` specifically.
The `Bulk_Plugin_Upgrader_Skin` class and the `Bulk_Theme_Upgrader_Skin` class both already allow for this, but the `wp_ajax_update_plugin()` and `wp_ajax_update_theme()` functions also call the `*_Upgrader::bulk_upgrade()` methods, so the `WP_Ajax_Upgrader_Skin` class also needs to have these properties explicitly declared.
Includes adding proper DocBlocks for the pre-existing properties in the `Bulk_Plugin_Upgrader_Skin` and the `Bulk_Theme_Upgrader_Skin` classes.
Follow-up to [13686], [37714], [38199], [42677], [42873], [53557], [53558], [53850], [53851], [53852], [53853], [53854], [53856], [53916], [53935], [53936], [53937], [53938], [53942], [53945], [53948], [53949].
Props jrf, costdev.
See #56033.
Built from https://develop.svn.wordpress.org/trunk@53952
git-svn-id: http://core.svn.wordpress.org/trunk@53511 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-08-29 14:46:10 +02:00
|
|
|
/**
|
|
|
|
* Plugin info.
|
|
|
|
*
|
|
|
|
* The Plugin_Upgrader::bulk_upgrade() method will fill this in
|
|
|
|
* with info retrieved from the get_plugin_data() function.
|
|
|
|
*
|
|
|
|
* @var array Plugin data. Values will be empty if not supplied by the plugin.
|
|
|
|
*/
|
|
|
|
public $plugin_info = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Theme info.
|
|
|
|
*
|
|
|
|
* The Theme_Upgrader::bulk_upgrade() method will fill this in
|
|
|
|
* with info retrieved from the Theme_Upgrader::theme_info() method,
|
|
|
|
* which in turn calls the wp_get_theme() function.
|
|
|
|
*
|
|
|
|
* @var WP_Theme|false The theme's info object, or false.
|
|
|
|
*/
|
|
|
|
public $theme_info = false;
|
|
|
|
|
2016-08-05 00:18:30 +02:00
|
|
|
/**
|
|
|
|
* Holds the WP_Error object.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
2020-07-28 13:57:03 +02:00
|
|
|
*
|
2016-08-05 00:18:30 +02:00
|
|
|
* @var null|WP_Error
|
|
|
|
*/
|
|
|
|
protected $errors = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
2020-07-28 13:57:03 +02:00
|
|
|
* Sets up the WordPress Ajax upgrader skin.
|
|
|
|
*
|
2016-08-05 00:18:30 +02:00
|
|
|
* @since 4.6.0
|
|
|
|
*
|
2020-07-28 13:57:03 +02:00
|
|
|
* @see WP_Upgrader_Skin::__construct()
|
|
|
|
*
|
|
|
|
* @param array $args Optional. The WordPress Ajax upgrader skin arguments to
|
|
|
|
* override default options. See WP_Upgrader_Skin::__construct().
|
|
|
|
* Default empty array.
|
2016-08-05 00:18:30 +02:00
|
|
|
*/
|
|
|
|
public function __construct( $args = array() ) {
|
|
|
|
parent::__construct( $args );
|
|
|
|
|
|
|
|
$this->errors = new WP_Error();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the list of errors.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
|
|
|
*
|
|
|
|
* @return WP_Error Errors during an upgrade.
|
|
|
|
*/
|
|
|
|
public function get_errors() {
|
|
|
|
return $this->errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a string for error messages.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
|
|
|
*
|
|
|
|
* @return string Error messages during an upgrade.
|
|
|
|
*/
|
|
|
|
public function get_error_messages() {
|
|
|
|
$messages = array();
|
|
|
|
|
|
|
|
foreach ( $this->errors->get_error_codes() as $error_code ) {
|
2018-02-27 03:31:31 +01:00
|
|
|
$error_data = $this->errors->get_error_data( $error_code );
|
|
|
|
|
|
|
|
if ( $error_data && is_string( $error_data ) ) {
|
|
|
|
$messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $error_data ) );
|
2016-08-05 00:18:30 +02:00
|
|
|
} else {
|
|
|
|
$messages[] = $this->errors->get_error_message( $error_code );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode( ', ', $messages );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-14 17:23:10 +01:00
|
|
|
* Stores an error message about the upgrade.
|
2016-08-05 00:18:30 +02:00
|
|
|
*
|
|
|
|
* @since 4.6.0
|
2019-10-09 06:28:02 +02:00
|
|
|
* @since 5.3.0 Formalized the existing `...$args` parameter by adding it
|
|
|
|
* to the function signature.
|
2016-08-05 00:18:30 +02:00
|
|
|
*
|
2019-09-15 12:42:54 +02:00
|
|
|
* @param string|WP_Error $errors Errors.
|
|
|
|
* @param mixed ...$args Optional text replacements.
|
2016-08-05 00:18:30 +02:00
|
|
|
*/
|
2019-09-15 12:42:54 +02:00
|
|
|
public function error( $errors, ...$args ) {
|
2016-08-05 00:18:30 +02:00
|
|
|
if ( is_string( $errors ) ) {
|
|
|
|
$string = $errors;
|
|
|
|
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
|
|
|
|
$string = $this->upgrader->strings[ $string ];
|
|
|
|
}
|
|
|
|
|
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( $string, '%' ) ) {
|
2016-08-05 00:18:30 +02:00
|
|
|
if ( ! empty( $args ) ) {
|
|
|
|
$string = vsprintf( $string, $args );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 16:14:52 +02:00
|
|
|
// Count existing errors to generate a unique error code.
|
2017-07-26 15:39:44 +02:00
|
|
|
$errors_count = count( $this->errors->get_error_codes() );
|
2019-05-31 16:14:52 +02:00
|
|
|
$this->errors->add( 'unknown_upgrade_error_' . ( $errors_count + 1 ), $string );
|
2016-08-05 00:18:30 +02:00
|
|
|
} elseif ( is_wp_error( $errors ) ) {
|
|
|
|
foreach ( $errors->get_error_codes() as $error_code ) {
|
|
|
|
$this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-15 12:42:54 +02:00
|
|
|
parent::error( $errors, ...$args );
|
2016-08-05 00:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-14 17:23:10 +01:00
|
|
|
* Stores a message about the upgrade.
|
2016-08-05 00:18:30 +02:00
|
|
|
*
|
|
|
|
* @since 4.6.0
|
2019-10-09 06:28:02 +02:00
|
|
|
* @since 5.3.0 Formalized the existing `...$args` parameter by adding it
|
|
|
|
* to the function signature.
|
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 `$data` to `$feedback` for PHP 8 named parameter support.
|
2016-08-05 00:18: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
|
|
|
* @param string|array|WP_Error $feedback Message data.
|
|
|
|
* @param mixed ...$args Optional text replacements.
|
2016-08-05 00:18: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 ( is_wp_error( $feedback ) ) {
|
|
|
|
foreach ( $feedback->get_error_codes() as $error_code ) {
|
|
|
|
$this->errors->add( $error_code, $feedback->get_error_message( $error_code ), $feedback->get_error_data( $error_code ) );
|
2016-08-05 00:18: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
|
|
|
parent::feedback( $feedback, ...$args );
|
2016-08-05 00:18:30 +02:00
|
|
|
}
|
|
|
|
}
|