mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01: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
This commit is contained in:
parent
a395d4c50e
commit
03331f52ff
@ -66,18 +66,20 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
|
||||
* Stores a message about the upgrade.
|
||||
*
|
||||
* @since 3.7.0
|
||||
* @since 5.9.0 Renamed `$data` to `$feedback` for PHP 8 named parameter support.
|
||||
*
|
||||
* @param string|array|WP_Error $data Message data.
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
* @param string|array|WP_Error $feedback Message data.
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function feedback( $data, ...$args ) {
|
||||
if ( is_wp_error( $data ) ) {
|
||||
$string = $data->get_error_message();
|
||||
} elseif ( is_array( $data ) ) {
|
||||
public function feedback( $feedback, ...$args ) {
|
||||
if ( is_wp_error( $feedback ) ) {
|
||||
$string = $feedback->get_error_message();
|
||||
} elseif ( is_array( $feedback ) ) {
|
||||
return;
|
||||
} else {
|
||||
$string = $data;
|
||||
$string = $feedback;
|
||||
}
|
||||
|
||||
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
|
||||
$string = $this->upgrader->strings[ $string ];
|
||||
}
|
||||
|
@ -49,28 +49,30 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
* @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.
|
||||
*/
|
||||
public function feedback( $string, ...$args ) {
|
||||
if ( isset( $this->upgrader->strings[ $string ] ) ) {
|
||||
$string = $this->upgrader->strings[ $string ];
|
||||
public function feedback( $feedback, ...$args ) {
|
||||
if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
|
||||
$feedback = $this->upgrader->strings[ $feedback ];
|
||||
}
|
||||
|
||||
if ( strpos( $string, '%' ) !== false ) {
|
||||
if ( strpos( $feedback, '%' ) !== false ) {
|
||||
if ( $args ) {
|
||||
$args = array_map( 'strip_tags', $args );
|
||||
$args = array_map( 'esc_html', $args );
|
||||
$string = vsprintf( $string, $args );
|
||||
$args = array_map( 'strip_tags', $args );
|
||||
$args = array_map( 'esc_html', $args );
|
||||
$feedback = vsprintf( $feedback, $args );
|
||||
}
|
||||
}
|
||||
if ( empty( $string ) ) {
|
||||
if ( empty( $feedback ) ) {
|
||||
return;
|
||||
}
|
||||
if ( $this->in_loop ) {
|
||||
echo "$string<br />\n";
|
||||
echo "$feedback<br />\n";
|
||||
} else {
|
||||
echo "<p>$string</p>\n";
|
||||
echo "<p>$feedback</p>\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,17 +121,18 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
|
||||
* @since 4.6.0
|
||||
* @since 5.3.0 Formalized the existing `...$args` parameter by adding it
|
||||
* to the function signature.
|
||||
* @since 5.9.0 Renamed `$data` to `$feedback` for PHP 8 named parameter support.
|
||||
*
|
||||
* @param string|array|WP_Error $data Message data.
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
* @param string|array|WP_Error $feedback Message data.
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function feedback( $data, ...$args ) {
|
||||
if ( is_wp_error( $data ) ) {
|
||||
foreach ( $data->get_error_codes() as $error_code ) {
|
||||
$this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) );
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
parent::feedback( $data, ...$args );
|
||||
parent::feedback( $feedback, ...$args );
|
||||
}
|
||||
}
|
||||
|
@ -186,26 +186,27 @@ class WP_Upgrader_Skin {
|
||||
|
||||
/**
|
||||
* @since 2.8.0
|
||||
* @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
|
||||
*
|
||||
* @param string $string
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
* @param string $feedback Message data.
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function feedback( $string, ...$args ) {
|
||||
if ( isset( $this->upgrader->strings[ $string ] ) ) {
|
||||
$string = $this->upgrader->strings[ $string ];
|
||||
public function feedback( $feedback, ...$args ) {
|
||||
if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
|
||||
$feedback = $this->upgrader->strings[ $feedback ];
|
||||
}
|
||||
|
||||
if ( strpos( $string, '%' ) !== false ) {
|
||||
if ( strpos( $feedback, '%' ) !== false ) {
|
||||
if ( $args ) {
|
||||
$args = array_map( 'strip_tags', $args );
|
||||
$args = array_map( 'esc_html', $args );
|
||||
$string = vsprintf( $string, $args );
|
||||
$args = array_map( 'strip_tags', $args );
|
||||
$args = array_map( 'esc_html', $args );
|
||||
$feedback = vsprintf( $feedback, $args );
|
||||
}
|
||||
}
|
||||
if ( empty( $string ) ) {
|
||||
if ( empty( $feedback ) ) {
|
||||
return;
|
||||
}
|
||||
show_message( $string );
|
||||
show_message( $feedback );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.9-alpha-51780';
|
||||
$wp_version = '5.9-alpha-51781';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user