2016-05-10 07:11:30 -04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-05-10 07:31:28 -04:00
|
|
|
* Upgrader API: Automatic_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
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-11-14 11:23:10 -05:00
|
|
|
* Upgrader Skin for Automatic WordPress Upgrades.
|
2016-05-10 07:11:30 -04:00
|
|
|
*
|
|
|
|
* This skin is designed to be used when no output is intended, all output
|
|
|
|
* is captured and stored for the caller to process and log/email/discard.
|
|
|
|
*
|
|
|
|
* @since 3.7.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 Bulk_Upgrader_Skin
|
2016-05-10 07:11:30 -04:00
|
|
|
*/
|
|
|
|
class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
|
|
|
|
protected $messages = array();
|
|
|
|
|
|
|
|
/**
|
2016-07-22 08:10:27 -04:00
|
|
|
* Determines whether the upgrader needs FTP/SSH details in order to connect
|
|
|
|
* to the filesystem.
|
2016-05-10 07:11:30 -04:00
|
|
|
*
|
2016-07-22 08:10:27 -04:00
|
|
|
* @since 3.7.0
|
|
|
|
* @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
|
|
|
|
*
|
|
|
|
* @see request_filesystem_credentials()
|
|
|
|
*
|
2019-10-26 19:16:04 -04:00
|
|
|
* @param bool|WP_Error $error Optional. Whether the current request has failed to connect,
|
|
|
|
* or an error object. Default false.
|
|
|
|
* @param string $context Optional. Full path to the directory that is tested
|
|
|
|
* for being writable. Default empty.
|
|
|
|
* @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
|
2016-07-22 08:10:27 -04:00
|
|
|
* @return bool True on success, false on failure.
|
2016-05-10 07:11:30 -04:00
|
|
|
*/
|
|
|
|
public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
|
|
|
|
if ( $context ) {
|
|
|
|
$this->options['context'] = $context;
|
|
|
|
}
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* TODO: Fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version.
|
|
|
|
* This will output a credentials form in event of failure. We don't want that, so just hide with a buffer.
|
|
|
|
*/
|
2016-05-10 07:11:30 -04:00
|
|
|
ob_start();
|
|
|
|
$result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
|
|
|
|
ob_end_clean();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-14 11:23:10 -05:00
|
|
|
* Retrieves the upgrade messages.
|
|
|
|
*
|
|
|
|
* @since 3.7.0
|
|
|
|
*
|
2021-05-07 16:16:00 -04:00
|
|
|
* @return string[] Messages during an upgrade.
|
2016-05-10 07:11:30 -04:00
|
|
|
*/
|
|
|
|
public function get_upgrade_messages() {
|
|
|
|
return $this->messages;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-14 11:23:10 -05:00
|
|
|
* Stores a message about the upgrade.
|
|
|
|
*
|
|
|
|
* @since 3.7.0
|
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 `$data` to `$feedback` for PHP 8 named parameter support.
|
2020-11-14 11:23:10 -05: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
|
|
|
* @param string|array|WP_Error $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 ( is_wp_error( $feedback ) ) {
|
|
|
|
$string = $feedback->get_error_message();
|
|
|
|
} elseif ( is_array( $feedback ) ) {
|
2016-05-10 07:11:30 -04:00
|
|
|
return;
|
|
|
|
} 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
|
|
|
$string = $feedback;
|
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
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
|
2016-05-10 07:11:30 -04:00
|
|
|
$string = $this->upgrader->strings[ $string ];
|
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( $string, '%' ) ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! empty( $args ) ) {
|
2016-05-10 07:11:30 -04:00
|
|
|
$string = vsprintf( $string, $args );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:11:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$string = trim( $string );
|
|
|
|
|
|
|
|
// Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
|
2017-11-30 18:11:00 -05:00
|
|
|
$string = wp_kses(
|
2018-08-16 21:51:36 -04:00
|
|
|
$string,
|
|
|
|
array(
|
2017-11-30 18:11:00 -05:00
|
|
|
'a' => array(
|
|
|
|
'href' => true,
|
|
|
|
),
|
|
|
|
'br' => true,
|
|
|
|
'em' => true,
|
|
|
|
'strong' => true,
|
|
|
|
)
|
|
|
|
);
|
2016-05-10 07:11:30 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( empty( $string ) ) {
|
2016-05-10 07:11:30 -04:00
|
|
|
return;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:11:30 -04:00
|
|
|
|
|
|
|
$this->messages[] = $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-14 11:23:10 -05:00
|
|
|
* Creates a new output buffer.
|
|
|
|
*
|
|
|
|
* @since 3.7.0
|
2016-05-10 07:11:30 -04:00
|
|
|
*/
|
|
|
|
public function header() {
|
|
|
|
ob_start();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-14 11:23:10 -05:00
|
|
|
* Retrieves the buffered content, deletes the buffer, and processes the output.
|
|
|
|
*
|
|
|
|
* @since 3.7.0
|
2016-05-10 07:11:30 -04:00
|
|
|
*/
|
|
|
|
public function footer() {
|
|
|
|
$output = ob_get_clean();
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! empty( $output ) ) {
|
2016-05-10 07:11:30 -04:00
|
|
|
$this->feedback( $output );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:11:30 -04:00
|
|
|
}
|
|
|
|
}
|