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 |
| 444 | 444 | * @param mixed ...$arg Optional. Additional arguments which are passed on to the |
| 445 | 445 | * functions hooked to the action. Default empty. |
| 446 | 446 | */ |
| 447 | | function do_action( $tag, $arg = '' ) { |
| | 447 | function do_action( $tag, ...$arg ) { |
| 448 | 448 | global $wp_filter, $wp_actions, $wp_current_filter; |
| 449 | 449 | |
| 450 | 450 | if ( ! isset( $wp_actions[ $tag ] ) ) { |
| … |
… |
function do_action( $tag, $arg = '' ) { |
| 471 | 471 | $wp_current_filter[] = $tag; |
| 472 | 472 | } |
| 473 | 473 | |
| 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[] = ''; |
| 482 | 476 | } |
| 483 | 477 | |
| 484 | | $wp_filter[ $tag ]->do_action( $args ); |
| | 478 | $wp_filter[ $tag ]->do_action( $arg ); |
| 485 | 479 | |
| 486 | 480 | array_pop( $wp_current_filter ); |
| 487 | 481 | } |