Skip to content
Permalink
Browse files

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
  • Loading branch information...
SergeyBiryukov committed Sep 26, 2019
1 parent 8c8999d commit 1c9f3e0a15324b7cdac42dd9b57b877e1e67b187
Showing with 5 additions and 9 deletions.
  1. +5 −9 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 );
}

0 comments on commit 1c9f3e0

Please sign in to comment.
You can’t perform that action at this time.