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.
Built from https://develop.svn.wordpress.org/trunk@46322


git-svn-id: http://core.svn.wordpress.org/trunk@46121 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-09-26 13:53:58 +00:00
parent abb00ee8a4
commit 8bb8e77ace
2 changed files with 6 additions and 10 deletions

View File

@ -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 );
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-beta1-46321';
$wp_version = '5.3-beta1-46322';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.