Code Modernisation: Introduce the spread operator in `wp-includes/formatting.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@46128


git-svn-id: http://core.svn.wordpress.org/trunk@45940 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-09-15 11:06:55 +00:00
parent 9e2c6eb624
commit 6a039a5731
2 changed files with 5 additions and 5 deletions

View File

@ -4836,8 +4836,7 @@ function wp_pre_kses_less_than_callback( $matches ) {
* @param mixed ...$args Arguments to be formatted into the $pattern string.
* @return string The formatted string.
*/
function wp_sprintf( $pattern ) {
$args = func_get_args();
function wp_sprintf( $pattern, ...$args ) {
$len = strlen( $pattern );
$start = 0;
$result = '';
@ -4867,11 +4866,12 @@ function wp_sprintf( $pattern ) {
if ( $pattern[ $start ] == '%' ) {
// Find numbered arguments or take the next one in order
if ( preg_match( '/^%(\d+)\$/', $fragment, $matches ) ) {
$arg = isset( $args[ $matches[1] ] ) ? $args[ $matches[1] ] : '';
$index = $matches[1] - 1; // 0-based array vs 1-based sprintf arguments.
$arg = isset( $args[ $index ] ) ? $args[ $index ] : '';
$fragment = str_replace( "%{$matches[1]}$", '%', $fragment );
} else {
++$arg_index;
$arg = isset( $args[ $arg_index ] ) ? $args[ $arg_index ] : '';
++$arg_index;
}
/**

View File

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