do_action( string $tag,  $arg = '' )

Execute functions hooked on a specific action hook.


Description

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().


Parameters

$tag

(string) (Required) The name of the action to be executed.

$arg,...

(mixed) (Optional) Additional arguments which are passed on to the functions hooked to the action. Default empty.


Source

File: wp-includes/plugin.php

function do_action($tag, $arg = '') {
	global $wp_filter, $wp_actions, $wp_current_filter;

	if ( ! isset($wp_actions[$tag]) )
		$wp_actions[$tag] = 1;
	else
		++$wp_actions[$tag];

	$all_args = func_get_args();

	// Do 'all' actions first
	if ( isset($wp_filter['all']) ) {
		$wp_current_filter[] = $tag;
		_wp_call_all_hook( $all_args );
	}

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

	if ( !isset($wp_filter['all']) )
		$wp_current_filter[] = $tag;

	$args = $all_args;
	array_shift( $args );

	if ( empty( $args ) ) {
		$args = array( '' );
	}

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

	array_pop($wp_current_filter);
}


Changelog

Changelog
Version Description
WP-1.2.0 Introduced.