Code Modernisation: Introduce the spread operator in wp-admin/includes/class-*-upgrader-skin.php
.
Rather than relying `func_get_args()` to retrieve arbitrary function arguments, we can now use the spread operator to assign them directly to a variable. Props jrf. See #47678. git-svn-id: https://develop.svn.wordpress.org/trunk@46125 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
1431a7a39f
commit
af246a6797
@ -58,8 +58,9 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
|
||||
|
||||
/**
|
||||
* @param string|array|WP_Error $data
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function feedback( $data ) {
|
||||
public function feedback( $data, ...$args ) {
|
||||
if ( is_wp_error( $data ) ) {
|
||||
$string = $data->get_error_message();
|
||||
} elseif ( is_array( $data ) ) {
|
||||
@ -72,8 +73,6 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
|
||||
}
|
||||
|
||||
if ( strpos( $string, '%' ) !== false ) {
|
||||
$args = func_get_args();
|
||||
$args = array_splice( $args, 1 );
|
||||
if ( ! empty( $args ) ) {
|
||||
$string = vsprintf( $string, $args );
|
||||
}
|
||||
|
@ -50,15 +50,14 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function feedback( $string ) {
|
||||
public function feedback( $string, ...$args ) {
|
||||
if ( isset( $this->upgrader->strings[ $string ] ) ) {
|
||||
$string = $this->upgrader->strings[ $string ];
|
||||
}
|
||||
|
||||
if ( strpos( $string, '%' ) !== false ) {
|
||||
$args = func_get_args();
|
||||
$args = array_splice( $args, 1 );
|
||||
if ( $args ) {
|
||||
$args = array_map( 'strip_tags', $args );
|
||||
$args = array_map( 'esc_html', $args );
|
||||
|
@ -78,9 +78,10 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
|
||||
*
|
||||
* @since 4.6.0
|
||||
*
|
||||
* @param string|WP_Error $errors Errors.
|
||||
* @param string|WP_Error $errors Errors.
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function error( $errors ) {
|
||||
public function error( $errors, ...$args ) {
|
||||
if ( is_string( $errors ) ) {
|
||||
$string = $errors;
|
||||
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
|
||||
@ -88,8 +89,6 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
|
||||
}
|
||||
|
||||
if ( false !== strpos( $string, '%' ) ) {
|
||||
$args = func_get_args();
|
||||
$args = array_splice( $args, 1 );
|
||||
if ( ! empty( $args ) ) {
|
||||
$string = vsprintf( $string, $args );
|
||||
}
|
||||
@ -104,8 +103,7 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
|
||||
}
|
||||
}
|
||||
|
||||
$args = func_get_args();
|
||||
call_user_func_array( array( $this, 'parent::error' ), $args );
|
||||
parent::error( $errors, ...$args );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,16 +111,16 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
|
||||
*
|
||||
* @since 4.6.0
|
||||
*
|
||||
* @param string|array|WP_Error $data Log entry data.
|
||||
* @param string|array|WP_Error $data Log entry data.
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function feedback( $data ) {
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
$args = func_get_args();
|
||||
call_user_func_array( array( $this, 'parent::feedback' ), $args );
|
||||
parent::feedback( $data, ...$args );
|
||||
}
|
||||
}
|
||||
|
@ -140,15 +140,14 @@ class WP_Upgrader_Skin {
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param mixed ...$args Optional text replacements.
|
||||
*/
|
||||
public function feedback( $string ) {
|
||||
public function feedback( $string, ...$args ) {
|
||||
if ( isset( $this->upgrader->strings[ $string ] ) ) {
|
||||
$string = $this->upgrader->strings[ $string ];
|
||||
}
|
||||
|
||||
if ( strpos( $string, '%' ) !== false ) {
|
||||
$args = func_get_args();
|
||||
$args = array_splice( $args, 1 );
|
||||
if ( $args ) {
|
||||
$args = array_map( 'strip_tags', $args );
|
||||
$args = array_map( 'esc_html', $args );
|
||||
|
Loading…
x
Reference in New Issue
Block a user