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
This commit is contained in:
Sergey Biryukov 2019-09-26 13:52:46 +00:00
parent 8c8999d933
commit 1c9f3e0a15

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