has_action( 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:599
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 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 $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_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
- 9
- Plugin surface
- None
- Called by
- 28
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 9.
Nothing here hands control to plugin code.
28 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 | 9 | 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: 9 instructions, 9 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 · 28
- 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.
- get_the_block_template_html()Returns the markup for the current template.
- wp_admin_bar_customize_menu()Adds the "Customize" link to the Toolbar.
Show all 28
- wp_enqueue_admin_bar_bump_styles()Enqueues inline bump styles to make room for the admin bar.
- 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 styles.
- wp_enqueue_embed_styles()Enqueues the CSS in the embed iframe header.
- wp_enqueue_emoji_styles()Enqueues the important emoji-related styles.
- wp_enqueue_global_styles()Enqueues the global styles defined via theme.json.
- wp_enqueue_img_auto_sizes_contain_css_fix()Enqueues a CSS rule to fix potential visual issues with images using `sizes=auto`.
- wp_enqueue_registered_block_scripts_and_styles()Enqueues registered block scripts and styles, depending on current rendered context (only enqueuing editor scripts while in context of the editor).
- wp_hoist_late_printed_styles()Adds the hooks needed for CSS output to be delayed until after the content of the page has been established.
- 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_oembed_add_discovery_links()Adds oEmbed discovery links in the head element of the website.
- 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.
- wp_should_output_buffer_template_for_enhancement()Checks whether the template should be output buffered for enhancement.
Source code
function has_action( $hook_name, $callback = false, $priority = false ) { return 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.1.0 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.