has_action( string $hook_name, callable|string|array|false $callback = false ): bool|int
- Since
- 2.5.0
- Source
wp-includes/plugin.php:588
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 2.5.0
- PHP
- 7.4–8.6-dev
- 6.7.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in every tracked release (6.7.10 to 7.1.3), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$hook_namestring- The name of the action 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
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.
Performance profile
How much work a call to has_action() 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
- Plugin surface
- None
- Called by
- 21
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. The body compiles to 7.
Nothing here hands control to plugin code.
21 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost has_action() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7 | 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: 7 instructions, 7 executed per call, 0 branches. 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.
Uses · 1
- has_filter()Checks if any filter has been registered for a hook.
Used by · 21
- WP_Customize_Manager::save_changeset_post()Saves the post for the loaded changeset.
- WP_Customize_Setting::preview()Add filters to supply the setting's value when accessed.
- WP_Customize_Setting::update()Save the value of the setting, using the related API.
- WP_Screen::render_meta_boxes_preferences()Renders the meta boxes preferences.
- _wp_get_iframed_editor_assets()Collect the block editor assets that need to be loaded into the editor's iframe.
- comment_form()Outputs a complete commenting form for use within a template.
- display_setup_form()Displays installer setup form.
- do_action_deprecated()Fires functions attached to a deprecated action hook.
- do_feed()Loads the feed template from the use of an action hook.
- get_plugin_page_hook()Gets the hook attached to the administrative page of a plugin.
- wp_admin_bar_customize_menu()Adds the "Customize" link to the Toolbar.
- wp_enqueue_admin_bar_bump_styles()Enqueues inline bump styles to make room for the admin bar.
Show all 21
- wp_enqueue_admin_bar_header_styles()Enqueues inline style to hide the admin bar when printing.
- wp_enqueue_block_template_skip_link()Enqueues the skip-link script & styles.
- wp_enqueue_embed_styles()Enqueues the CSS in the embed iframe header.
- wp_enqueue_emoji_styles()Enqueues the important emoji-related styles.
- wp_insert_site()Inserts a new site into the database.
- wp_is_local_html_output()Checks whether a given HTML string is likely an output from this WordPress site.
- wp_maybe_enqueue_oembed_host_js()Enqueue the wp-embed script if the provided oEmbed HTML contains a post embed.
- wp_save_post_revision()Creates a revision for the current version of a post.
- wp_save_post_revision_on_insert()Saves revisions for a post after all changes have been made.
Source code
function has_action( $hook_name, $callback = false ) { return has_filter( $hook_name, $callback );}Changelog
Introduced in 2.5.0. One change between 6.7.10 and 7.1.3.
Signature, return type and hooks compared across 5 parsed releases.
$priority added.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.11 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.