Make WordPress Core


Ignore:
Timestamp:
09/15/2019 10:32:54 AM (6 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/category-template.php

    r45932 r46123  
    10571057 * @uses Walker_Category to create HTML list content.
    10581058 * @since 2.1.0
    1059  * @see Walker_Category::walk() for parameters and return description.
     1059 * @see Walker::walk() for parameters and return description.
     1060 *
     1061 * @param mixed ...$args Elements array, maximum hierarchical depth and optional additional arguments.
    10601062 * @return string
    10611063 */
    1062 function walk_category_tree() {
    1063     $args = func_get_args();
    1064     // the user's options are the third parameter
     1064function walk_category_tree( ...$args ) {
     1065    // The user's options are the third parameter.
    10651066    if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
    10661067        $walker = new Walker_Category;
     
    10681069        $walker = $args[2]['walker'];
    10691070    }
    1070     return call_user_func_array( array( $walker, 'walk' ), $args );
     1071    return $walker->walk( ...$args );
    10711072}
    10721073
     
    10761077 * @uses Walker_CategoryDropdown to create HTML dropdown content.
    10771078 * @since 2.1.0
    1078  * @see Walker_CategoryDropdown::walk() for parameters and return description.
     1079 * @see Walker::walk() for parameters and return description.
     1080 *
     1081 * @param mixed ...$args Elements array, maximum hierarchical depth and optional additional arguments.
    10791082 * @return string
    10801083 */
    1081 function walk_category_dropdown_tree() {
    1082     $args = func_get_args();
    1083     // the user's options are the third parameter
     1084function walk_category_dropdown_tree( ...$args ) {
     1085    // The user's options are the third parameter.
    10841086    if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
    10851087        $walker = new Walker_CategoryDropdown;
     
    10871089        $walker = $args[2]['walker'];
    10881090    }
    1089     return call_user_func_array( array( $walker, 'walk' ), $args );
     1091    return $walker->walk( ...$args );
    10901092}
    10911093
Note: See TracChangeset for help on using the changeset viewer.