WordPress at Your Fingertips

do_action_ref_array() WP 1.0

Execute functions hooked on a specific action hook, specifying arguments in an array.

No Hooks.

Return

null. Nothing.

Usage

do_action_ref_array( $hook_name, $args );
$hook_name(string) (required)
The name of the action to be executed.
$args(array) (required)
The arguments supplied to the functions hooked to (hook_name).

Notes

  • See: do_action() This function is identical, but the arguments passed to the
    functions hooked to (hook_name) supplied using an array.
  • Global. WP_Hook[]. $wp_filter Stores all of the filters and actions.
  • Global. Int[]. $wp_actions Stores the number of times each action was triggered.
  • Global. String[]. $wp_current_filter Stores the list of current filters with the current one last.

Changelog

Since 2.1.0 Introduced.

Code of do_action_ref_array() WP 5.8

<?php
function do_action_ref_array( $hook_name, $args ) {
	global $wp_filter, $wp_actions, $wp_current_filter;

	if ( ! isset( $wp_actions[ $hook_name ] ) ) {
		$wp_actions[ $hook_name ] = 1;
	} else {
		++$wp_actions[ $hook_name ];
	}

	// Do 'all' actions first.
	if ( isset( $wp_filter['all'] ) ) {
		$wp_current_filter[] = $hook_name;
		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
		_wp_call_all_hook( $all_args );
	}

	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
		if ( isset( $wp_filter['all'] ) ) {
			array_pop( $wp_current_filter );
		}

		return;
	}

	if ( ! isset( $wp_filter['all'] ) ) {
		$wp_current_filter[] = $hook_name;
	}

	$wp_filter[ $hook_name ]->do_action( $args );

	array_pop( $wp_current_filter );
}

From tag: Actions (hooks)

More from category: Hooks (actions, filters)

No comments
    Log In