Make WordPress Core

Changeset 46322


Ignore:
Timestamp:
09/26/2019 01:52:46 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Code Modernisation: Introduce the spread operator in do_action().

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.

Props jrf.
See #47678.

File:
1 edited

Legend:

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

    r46220 r46322  
    440440 *                       functions hooked to the action. Default empty.
    441441 */
    442 function do_action( $tag, $arg = '' ) {
     442function do_action( $tag, ...$arg ) {
    443443    global $wp_filter, $wp_actions, $wp_current_filter;
    444444
     
    449449    }
    450450
    451     $all_args = func_get_args();
    452 
    453451    // Do 'all' actions first
    454452    if ( isset( $wp_filter['all'] ) ) {
    455453        $wp_current_filter[] = $tag;
     454        $all_args            = func_get_args();
    456455        _wp_call_all_hook( $all_args );
    457456    }
     
    468467    }
    469468
    470     $args = $all_args;
    471     array_shift( $args );
    472 
    473     if ( empty( $args ) ) {
    474         $args = array( '' );
    475     }
    476 
    477     $wp_filter[ $tag ]->do_action( $args );
     469    if ( empty( $arg ) ) {
     470        $arg[] = '';
     471    }
     472
     473    $wp_filter[ $tag ]->do_action( $arg );
    478474
    479475    array_pop( $wp_current_filter );
Note: See TracChangeset for help on using the changeset viewer.