WordPress.org

Make WordPress Core

Ticket #47678: 47678-do_action.patch

File 47678-do_action.patch, 1.5 KB (added by jrf, 7 months ago)

Simplify & modernize do_action()

  • src/wp-includes/plugin.php

    From 845dc765efc73c616f7f750e8d3121712780dfda Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Thu, 18 Jul 2019 06:18:27 +0200
    Subject: [PATCH] Simplify & modernize do_action()
    
    ---
     src/wp-includes/plugin.php | 14 ++++----------
     1 file changed, 4 insertions(+), 10 deletions(-)
    
    diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php
    index 16a88a21e1..7c40389f90 100644
    a b function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 
    444444 * @param mixed  ...$arg Optional. Additional arguments which are passed on to the
    445445 *                       functions hooked to the action. Default empty.
    446446 */
    447 function do_action( $tag, $arg = '' ) {
     447function do_action( $tag, ...$arg ) {
    448448        global $wp_filter, $wp_actions, $wp_current_filter;
    449449
    450450        if ( ! isset( $wp_actions[ $tag ] ) ) {
    function do_action( $tag, $arg = '' ) { 
    471471                $wp_current_filter[] = $tag;
    472472        }
    473473
    474         $args = array();
    475         if ( is_array( $arg ) && 1 == count( $arg ) && isset( $arg[0] ) && is_object( $arg[0] ) ) { // array(&$this)
    476                 $args[] =& $arg[0];
    477         } else {
    478                 $args[] = $arg;
    479         }
    480         for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) {
    481                 $args[] = func_get_arg( $a );
     474        if ( empty( $arg ) ) {
     475                $arg[] = '';
    482476        }
    483477
    484         $wp_filter[ $tag ]->do_action( $args );
     478        $wp_filter[ $tag ]->do_action( $arg );
    485479
    486480        array_pop( $wp_current_filter );
    487481}