do_action


do_action ( $tag, $arg )

Parameters:
  • (string) $tag The name of the action to be executed.
  • (mixed) $arg ...$arg Optional. Additional arguments which are passed on to the functions hooked to the action. Default empty.
Defined at:
Change Log:
  • 5: .

Description

Execute functions hooked on a specific action hook.

This function invokes all functions attached to action hook $tag. It is possible to create new action hooks by simply calling this function, specifying the name of the new hook using the $tag parameter.

You can pass extra arguments to the hooks, much like you can with apply_filters().

Example usage:

// The action callback function
function example_callback( $arg1, $arg2 ) {
    // (maybe) do something with the args
}
add_action( 'example_action', 'example_callback', 10, 2 );

/*
 * Trigger the actions by calling the 'example_callback()' function that's
 * hooked onto `example_action` above.
 *
 * - 'example_action' is the action hook
 * - $arg1 and $arg2 are the additional arguments passed to the callback.
$value = do_action( 'example_action', $arg1, $arg2 );

Related Functions

doing_action, did_action, add_action, has_action, remove_action

Top Google Results

User discussions

wpseek mobile