From fcdd54cbcd2540955b591a6cd938b7ef50b4614f 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, 5 insertions(+), 9 deletions(-)
diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php
index 1f6cacd5b4..02957ee041 100644
|
a
|
b
|
function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 |
| 439 | 439 | * @param mixed ...$arg Optional. Additional arguments which are passed on to the |
| 440 | 440 | * functions hooked to the action. Default empty. |
| 441 | 441 | */ |
| 442 | | function do_action( $tag, $arg = '' ) { |
| | 442 | function do_action( $tag, ...$arg ) { |
| 443 | 443 | global $wp_filter, $wp_actions, $wp_current_filter; |
| 444 | 444 | |
| 445 | 445 | if ( ! isset( $wp_actions[ $tag ] ) ) { |
| … |
… |
function do_action( $tag, $arg = '' ) { |
| 448 | 448 | ++$wp_actions[ $tag ]; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | | $all_args = func_get_args(); |
| 452 | | |
| 453 | 451 | // Do 'all' actions first |
| 454 | 452 | if ( isset( $wp_filter['all'] ) ) { |
| 455 | 453 | $wp_current_filter[] = $tag; |
| | 454 | $all_args = func_get_args(); |
| 456 | 455 | _wp_call_all_hook( $all_args ); |
| 457 | 456 | } |
| 458 | 457 | |
| … |
… |
function do_action( $tag, $arg = '' ) { |
| 467 | 466 | $wp_current_filter[] = $tag; |
| 468 | 467 | } |
| 469 | 468 | |
| 470 | | $args = $all_args; |
| 471 | | array_shift( $args ); |
| 472 | | |
| 473 | | if ( empty( $args ) ) { |
| 474 | | $args = array( '' ); |
| | 469 | if ( empty( $arg ) ) { |
| | 470 | $arg[] = ''; |
| 475 | 471 | } |
| 476 | 472 | |
| 477 | | $wp_filter[ $tag ]->do_action( $args ); |
| | 473 | $wp_filter[ $tag ]->do_action( $arg ); |
| 478 | 474 | |
| 479 | 475 | array_pop( $wp_current_filter ); |
| 480 | 476 | } |