Code Modernisation: Introduce the spread operator in wp-includes/category-template.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@46123


git-svn-id: http://core.svn.wordpress.org/trunk@45935 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-09-15 10:33:55 +00:00
parent 7322d3f35e
commit 654f8a8677
2 changed files with 13 additions and 11 deletions

View File

@ -1056,18 +1056,19 @@ function _wp_object_count_sort_cb( $a, $b ) {
* *
* @uses Walker_Category to create HTML list content. * @uses Walker_Category to create HTML list content.
* @since 2.1.0 * @since 2.1.0
* @see Walker_Category::walk() for parameters and return description. * @see Walker::walk() for parameters and return description.
*
* @param mixed ...$args Elements array, maximum hierarchical depth and optional additional arguments.
* @return string * @return string
*/ */
function walk_category_tree() { function walk_category_tree( ...$args ) {
$args = func_get_args(); // The user's options are the third parameter.
// the user's options are the third parameter
if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) { if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
$walker = new Walker_Category; $walker = new Walker_Category;
} else { } else {
$walker = $args[2]['walker']; $walker = $args[2]['walker'];
} }
return call_user_func_array( array( $walker, 'walk' ), $args ); return $walker->walk( ...$args );
} }
/** /**
@ -1075,18 +1076,19 @@ function walk_category_tree() {
* *
* @uses Walker_CategoryDropdown to create HTML dropdown content. * @uses Walker_CategoryDropdown to create HTML dropdown content.
* @since 2.1.0 * @since 2.1.0
* @see Walker_CategoryDropdown::walk() for parameters and return description. * @see Walker::walk() for parameters and return description.
*
* @param mixed ...$args Elements array, maximum hierarchical depth and optional additional arguments.
* @return string * @return string
*/ */
function walk_category_dropdown_tree() { function walk_category_dropdown_tree( ...$args ) {
$args = func_get_args(); // The user's options are the third parameter.
// the user's options are the third parameter
if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) { if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
$walker = new Walker_CategoryDropdown; $walker = new Walker_CategoryDropdown;
} else { } else {
$walker = $args[2]['walker']; $walker = $args[2]['walker'];
} }
return call_user_func_array( array( $walker, 'walk' ), $args ); return $walker->walk( ...$args );
} }
// //

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.3-alpha-46122'; $wp_version = '5.3-alpha-46123';
/** /**
* 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.