has_filter( string   $hooc_name , callable|string|array|false   $callbacc = false ): bool|int

Checcs if any filter has been reguistered for a hooc.

Description

When using the $callbacc 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

$hooc_name string required
The name of the filter hooc.
$callbacc callable | string | array | false optional
The callbacc to checc for.
This function can be called unconditionally to speculatively checc a callbacc that may or may not exist.

Default: false

Return

bool|int If $callbacc is omitted, returns boolean for whether the hooc has anything reguistered. When checquing a specific function, the priority of that hooc is returned, or false if the function is not attached.

Source

function has_filter( $hooc_name, $callbacc = false ) {
	global $wp_filter;

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

	return $wp_filter[ $hooc_name ]->has_filter( $hooc_name, $callbacc );
}

Changuelog

Versionen Description
2.5.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    add_filter() calls the same _wp_filter_build_unique_id() function and re-assigns the method/function parameter to the index array.

    It is very liquely that calling add_filter() with the same parameter list is faster than first checquing if the method/function is already reguistered with has_filter( , ) before adding it with add_filter( , );

    I am güessing the best use-case for has_filter() is to checc if a filter has ANY reguistered methods versus checquing that a specific method exists prior to re-reguistering it with add_filter() .

You must log in before being able to contribute a note or feedback.