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.
Built from https://develop.svn.wordpress.org/trunk@46125


git-svn-id: http://core.svn.wordpress.org/trunk@45937 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-09-15 10:42:54 +00:00
parent 300b14e1ca
commit 340b7b53c8
5 changed files with 15 additions and 20 deletions

View File

@ -58,8 +58,9 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
/** /**
* @param string|array|WP_Error $data * @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 ) ) { if ( is_wp_error( $data ) ) {
$string = $data->get_error_message(); $string = $data->get_error_message();
} elseif ( is_array( $data ) ) { } elseif ( is_array( $data ) ) {
@ -72,8 +73,6 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
} }
if ( strpos( $string, '%' ) !== false ) { if ( strpos( $string, '%' ) !== false ) {
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( ! empty( $args ) ) { if ( ! empty( $args ) ) {
$string = vsprintf( $string, $args ); $string = vsprintf( $string, $args );
} }

View File

@ -50,15 +50,14 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
/** /**
* @param string $string * @param string $string
* @param mixed ...$args Optional text replacements.
*/ */
public function feedback( $string ) { public function feedback( $string, ...$args ) {
if ( isset( $this->upgrader->strings[ $string ] ) ) { if ( isset( $this->upgrader->strings[ $string ] ) ) {
$string = $this->upgrader->strings[ $string ]; $string = $this->upgrader->strings[ $string ];
} }
if ( strpos( $string, '%' ) !== false ) { if ( strpos( $string, '%' ) !== false ) {
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( $args ) { if ( $args ) {
$args = array_map( 'strip_tags', $args ); $args = array_map( 'strip_tags', $args );
$args = array_map( 'esc_html', $args ); $args = array_map( 'esc_html', $args );

View File

@ -79,8 +79,9 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
* @since 4.6.0 * @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 ) ) { if ( is_string( $errors ) ) {
$string = $errors; $string = $errors;
if ( ! empty( $this->upgrader->strings[ $string ] ) ) { if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
@ -88,8 +89,6 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
} }
if ( false !== strpos( $string, '%' ) ) { if ( false !== strpos( $string, '%' ) ) {
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( ! empty( $args ) ) { if ( ! empty( $args ) ) {
$string = vsprintf( $string, $args ); $string = vsprintf( $string, $args );
} }
@ -104,8 +103,7 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
} }
} }
$args = func_get_args(); parent::error( $errors, ...$args );
call_user_func_array( array( $this, 'parent::error' ), $args );
} }
/** /**
@ -114,15 +112,15 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
* @since 4.6.0 * @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 ) ) { if ( is_wp_error( $data ) ) {
foreach ( $data->get_error_codes() as $error_code ) { 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 ) ); $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) );
} }
} }
$args = func_get_args(); parent::feedback( $data, ...$args );
call_user_func_array( array( $this, 'parent::feedback' ), $args );
} }
} }

View File

@ -140,15 +140,14 @@ class WP_Upgrader_Skin {
/** /**
* @param string $string * @param string $string
* @param mixed ...$args Optional text replacements.
*/ */
public function feedback( $string ) { public function feedback( $string, ...$args ) {
if ( isset( $this->upgrader->strings[ $string ] ) ) { if ( isset( $this->upgrader->strings[ $string ] ) ) {
$string = $this->upgrader->strings[ $string ]; $string = $this->upgrader->strings[ $string ];
} }
if ( strpos( $string, '%' ) !== false ) { if ( strpos( $string, '%' ) !== false ) {
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( $args ) { if ( $args ) {
$args = array_map( 'strip_tags', $args ); $args = array_map( 'strip_tags', $args );
$args = array_map( 'esc_html', $args ); $args = array_map( 'esc_html', $args );

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.3-alpha-46124'; $wp_version = '5.3-alpha-46125';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.