From 1c9f3e0a15324b7cdac42dd9b57b877e1e67b187 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 26 Sep 2019 13:52:46 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@46322 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 c83ebdb81f..22ead3632b 100644 --- a/src/wp-includes/plugin.php +++ b/src/wp-includes/plugin.php @@ -439,7 +439,7 @@ function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 * @param mixed ...$arg Optional. Additional arguments which are passed on to the * functions hooked to the action. Default empty. */ -function do_action( $tag, $arg = '' ) { +function do_action( $tag, ...$arg ) { global $wp_filter, $wp_actions, $wp_current_filter; if ( ! isset( $wp_actions[ $tag ] ) ) { @@ -448,11 +448,10 @@ function do_action( $tag, $arg = '' ) { ++$wp_actions[ $tag ]; } - $all_args = func_get_args(); - // Do 'all' actions first if ( isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; + $all_args = func_get_args(); _wp_call_all_hook( $all_args ); } @@ -467,14 +466,11 @@ function do_action( $tag, $arg = '' ) { $wp_current_filter[] = $tag; } - $args = $all_args; - array_shift( $args ); - - if ( empty( $args ) ) { - $args = array( '' ); + if ( empty( $arg ) ) { + $arg[] = ''; } - $wp_filter[ $tag ]->do_action( $args ); + $wp_filter[ $tag ]->do_action( $arg ); array_pop( $wp_current_filter ); }