GC_Hook::has_filter()
最后更新于:2021-11-27 21:19:11
GC_Hook::has_filter( string$hook_name=”, callable|false$callback=false)Checks if a specific callback has been registered for this hook.
参数
- $hook_name
-
(string) (Optional) The name of the filter hook.
Default value: ”
- $callback
-
(callable|false) (Optional) The callback to check for.
Default value: 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.
源文件
文件: gc-includes/class-gc-hook.php
public function has_filter( $hook_name = '', $callback = false ) {
if ( false === $callback ) {
return $this->has_filters();
}
$function_key = _gc_filter_build_unique_id( $hook_name, $callback, false );
if ( ! $function_key ) {
return false;
}
foreach ( $this->callbacks as $priority => $callbacks ) {
if ( isset( $callbacks[ $function_key ] ) ) {
return $priority;
}
}
return false;
}