has_action

函式
has_action ( $hook_name, $callback = false )
引數
  • (string) $hook_name The name of the action hook.
    Required:
  • (callable|string|array|false) $callback Optional. The callback to check for. This function can be called unconditionally to speculatively check a callback that may or may not exist. Default false.
    Required:
    Default: false
返回值
  • (bool|int) If `$callback` 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.
相關
  • has_filter()
定義位置
相關方法
add_actiondo_actiondid_actiondoing_actionhas_category
引入
2.5.0
棄用
-

has_action: 這是一個WordPress的函式,用來檢查是否有任何動作鉤子被註冊為一個給定的動作: 該函式將動作名稱作為引數,如果有任何註冊的動作鉤子,則返回一個布林值,即true,否則為false。

檢查是否有任何動作被註冊為鉤子。

當使用`$callback`引數時,該函式可能會返回一個非布林值,評估為false(例如0),所以使用`===`操作符來測試返回值。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function has_action( $hook_name, $callback = false ) {
return has_filter( $hook_name, $callback );
}
function has_action( $hook_name, $callback = false ) { return has_filter( $hook_name, $callback ); }
function has_action( $hook_name, $callback = false ) {
	return has_filter( $hook_name, $callback );
}

常見問題

FAQs
檢視更多 >