has_filter

函式
has_filter ( $hook_name, $callback = false )
引數
  • (string) $hook_name The name of the filter 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.
定義位置
相關方法
add_filterhas_termapply_filtersdid_filterwp_list_filter
引入
2.5.0
棄用
-

has_filter – 這是一個PHP函式,用來檢查一個特定的過濾器是否已經被定義。過濾器是WordPress的一個核心概念,允許開發者通過掛鉤特定的動作或過濾器來修改核心函式和外掛的行為。has_filter函式需要兩個引數:第一個是過濾器的名稱,第二個是過濾器的可選優先順序。

檢查是否有任何過濾器被註冊為鉤子。

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function has_filter( $hook_name, $callback = false ) {
global $wp_filter;
if ( ! isset( $wp_filter[ $hook_name ] ) ) {
return false;
}
return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback );
}
function has_filter( $hook_name, $callback = false ) { global $wp_filter; if ( ! isset( $wp_filter[ $hook_name ] ) ) { return false; } return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback ); }
function has_filter( $hook_name, $callback = false ) {
	global $wp_filter;

	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
		return false;
	}

	return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback );
}

常見問題

FAQs
檢視更多 >