has_action

Check if any action has been registered for a hook.

Description

(bool|int) has_action( (string) $tag, (constant) $function_to_check = false ); 

Returns (bool|int)

If $function_to_check is omitted, returns boolean for whether the hook has anything registered. When checking a specific function, the priority of that hook is returned, or false if the function is not attached. When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false (e.g.) 0, so use the === operator for testing the return value.

Parameters (2)

0. $tag (string)
The name of the action hook.
1. $function_to_check — Optional. (constant) => false
The callback to check for. Default false.

Usage

  1. if ( !function_exists( 'has_action' ) ) { 
  2. require_once ABSPATH . WPINC . '/plugin.php'; 
  3.  
  4. // The name of the action hook. 
  5. $tag = ''; 
  6.  
  7. // Optional. The callback to check for. Default false. 
  8. $function_to_check = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = has_action($tag, $function_to_check); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/plugin.php  
  1. function has_action($tag, $function_to_check = false) { 
  2. return has_filter($tag, $function_to_check);