did_action() WordPress Function

The did_action() function is a conditional function that is used to check if a specific action has already been executed. This function is commonly used to check if a particular action hook has already been fired. If the action has not been executed, this function will return false.

did_action( string $hook_name ) #

Retrieves the number of times an action has been fired during the current request.


Parameters

$hook_name

(string)(Required)The name of the action hook.


Top ↑

Return

(int) The number of times the action hook has been fired.


Top ↑

Source

File: wp-includes/plugin.php

function did_action( $hook_name ) {
	global $wp_actions;

	if ( ! isset( $wp_actions[ $hook_name ] ) ) {
		return 0;
	}

	return $wp_actions[ $hook_name ];
}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.