WordPress.org

Make WordPress Core

Changeset 46442


Ignore:
Timestamp:
10/08/2019 05:54:45 PM (13 days ago)
Author:
SergeyBiryukov
Message:

Code Modernisation: Introduce the spread operator in Walker::walk() and ::paged_walk().

Rather than relying on func_get_args() to retrieve arbitrary function arguments, we can now use the spread operator to assign them directly to a variable.

This re-applies [45624] and reverts [45640], with a dev note upcoming for plugin authors to maintain backward compatibility with old versions of WordPress.

Props jrf.
See #47678.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-walker.php

    r46143 r46442  
    181181     * @param array $elements  An array of elements.
    182182     * @param int   $max_depth The maximum hierarchical depth.
     183     * @param mixed ...$args   Optional additional arguments.
    183184     * @return string The hierarchical item output.
    184185     */
    185     public function walk( $elements, $max_depth ) {
    186         $args   = array_slice( func_get_args(), 2 );
     186    public function walk( $elements, $max_depth, ...$args ) {
    187187        $output = '';
    188188
     
    273273     * @param array $elements
    274274     * @param int   $max_depth The maximum hierarchical depth.
    275      * @param int   $page_num The specific page number, beginning with 1.
     275     * @param int   $page_num  The specific page number, beginning with 1.
    276276     * @param int   $per_page
     277     * @param mixed ...$args   Optional additional arguments.
    277278     * @return string XHTML of the specified page of elements
    278279     */
    279     public function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
     280    public function paged_walk( $elements, $max_depth, $page_num, $per_page, ...$args ) {
    280281        if ( empty( $elements ) || $max_depth < -1 ) {
    281282            return '';
    282283        }
    283284
    284         $args   = array_slice( func_get_args(), 4 );
    285285        $output = '';
    286286
Note: See TracChangeset for help on using the changeset viewer.