has_action()判断一个动作钩子是否注册了某个回调方法

目录

描述

Check if any action has been registered for a hook.

has_action() 描述

用法

<?php has_action$tag$function_to_check ?>

has_action() 用法

参数

$tag

(string) (必填) The name of the action hook.

默认值: None

$function_to_check

(callback) (可选) If specified, return the priority of that function on this hook or false if not attached.

默认值: false

has_action() 参数

返回值

(integer|boolean) 

Optionally returns the priority on that hook for the specified function.

has_action() 返回值

注意

  • See has_filter() has_action is an alias of has_filter().
  • Since this 动作 is an alias of has_filter() it also uses the global array $wp_filter that stores all of the 过滤器s / 动作s.

has_action() 注意

历史

添加于 版本: 2.5

has_action() 历史

源文件

has_action() 函数的代码位于 wp-includes/plugin.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Check if any action has been registered for a hook.
 *
 * @since 2.5.0
 *
 * @see has_filter() has_action() is an alias of has_filter().
 *
 * @param string        $tag               The name of the action hook.
 * @param callback|bool $function_to_check Optional. The callback to check for. Default false.
 * @return 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.
 */
function has_action($tag, $function_to_check = false) {
	return has_filter($tag, $function_to_check);
}

has_action() 源文件

相关