has_filter( string $hook_name, callable|string|array|false $callback = false, int|false $priority = false ): bool|int
- Since
- 2.5.0, 6.9.0
- Source
wp-includes/plugin.php:286
Description
When using the $callback 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.
Compatibility
- WordPress
- since 6.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$hook_namestring- The name of the filter hook.
$callbackcallable|string|array|falseoptional- The callback to check for.
This function can be called unconditionally to speculatively check a callback that may or may not exist. Default false.Default:false $priorityint|falseoptional- The specific priority at which to check for the callback.
Default false.Default:false
Return value
bool|int- If
$callbackis 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.
If$callbackand$priorityare both provided, a boolean is returned for whether the specific function is registered at that priority.
Performance profile
How much work a call to has_filter() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 7–13
- Plugin surface
- None
- Called by
- 27
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 14.
Nothing here hands control to plugin code.
27 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost has_filter() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($wp_filter[$hook_name]) | 7 | none |
isset($wp_filter[$hook_name]) | 13 | ->has_filter() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 14 instructions, 7–13 executed per call, 1 branch. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Used by · 27
- Core_Upgrader::upgrade()Upgrades WordPress core.
- WP::build_query_string()Sets the query string property based off of the query variable property.
- WP_Customize_Nav_Menu_Item_Setting::preview()Handle previewing the setting.
- WP_Embed::shortcode()The do_shortcode() callback function.
- WP_MS_Sites_List_Table::column_plugins()Handles the plugins column output.
- WP_MS_Sites_List_Table::get_columns()Gets an array of column titles keyed by their column name.
- WP_Site_Health::check_wp_version_check_exists()Tests whether `wp_version_check` is blocked.
- WP_Site_Health::detect_plugin_theme_auto_update_issues()Checks for potential issues with plugin and theme auto-updates.
- WP_Site_Health_Auto_Updates::test_wp_version_check_attached()Checks if updates are intercepted by a filter.
- WP_Widget_Text::widget()Outputs the content for the current Text widget instance.
- _WP_Editors::editor()Outputs the HTML for a single instance of the editor.
- _restore_wpautop_hook()If do_blocks() needs to remove wpautop() from the `the_content` filter, this re-adds it afterwards, for subsequent `the_content` usage.
Show all 27
- apply_block_hooks_to_content()Runs the hooked blocks algorithm on the given content.
- apply_filters_deprecated()Fires functions attached to a deprecated filter hook.
- core_auto_updates_settings()Display WordPress auto-updates settings.
- do_blocks()Parses dynamic blocks out of `post_content` and re-renders them.
- do_shortcode()Searches content for shortcodes and filter shortcodes through their hooks.
- has_action()Checks if any action has been registered for a hook.
- inject_ignored_hooked_blocks_metadata_attributes()Inject ignoredHookedBlocks metadata attributes into a template or template part.
- insert_hooked_blocks_into_rest_response()Hooks into the REST API response for the Posts endpoint and adds the first and last inner blocks.
- map_meta_cap()Maps a capability to the primitive capabilities required of the given user to satisfy the capability being checked.
- register_meta()Registers a meta key.
- sanitize_meta()Sanitizes meta value.
- update_sitemeta_cache()Updates metadata cache for list of site IDs.
- wp_should_output_buffer_template_for_enhancement()Checks whether the template should be output buffered for enhancement.
- wp_update_comment()Updates an existing comment in the database.
- wpdb::placeholder_escape()Generates and returns a placeholder escape string for use in queries returned by ::prepare().
Source code
function has_filter( $hook_name, $callback = false, $priority = false ) { global $wp_filter; if ( ! isset( $wp_filter[ $hook_name ] ) ) { return false; } return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback, $priority );}Changelog
Introduced in 2.5.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$priority added.verified against source$priority parameter.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/plugin.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.