Creating an answer based upon responses via comments on original question of: Is it possible to create an action hook using do_action() within add_action()?
Yes it is possible to create an action hook using do_action()
on a call to add_action()
.
For clarification, the following code does NOT work:
add_action('init', do_action('my-hook-name'));
As stated by @IvanHanák
in the comments to the original question asked; It is possible to create an action hook using do_action()
on a call to add_action()
by using anonymous functions.
An example of creating an action hook using do_action()
on a call to add_action()
using anonymous functions:
add_action('some-existing-hook-name', function(){do_action('my-new-hook-name');});
However, it should be noted that using anonymous functions can make it difficult to debug or remove hooks.
Related Posts:
- Difference Between Filter and Action Hooks?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- How do I Make a Theme “plugin-ready”?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Define a function outside a class and call the function using action or filter hook
- Woocommerce – Hide a Column in Cart Table
- Namespaced action and filter tags
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- How to get all queries’s results after they have executed?
- Hook add_attachment error
- Call to undefined function is_home() or any conditional tags
- How to find list of all functions bind to a particular hook from my plugin?
- apply_filters() and call_user_func() to define and call a function outside a class
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- Add_action not calling callback function
- Apply function on all action hooks?
- Ninja Forms: Front-End Forms, Post ID?
- How to create an API for my plugin?
- Which hook should be used to add an action containing a redirect?
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- add_filter OO with parameters
- How Do I Load My Action Earlier Enough?
- Does WP fire delete_post when trashed posts are automatically deleted?
- What’s the earliest point I can get the queried object ID?
- How to modify post content before writing to database?
- Actions or filters fired when data is saved in a custom table
- How can I hook into existing WordPress Bulk actions?
- Hook for post permalink update
- Dynamically Override Fancy Title
- Get returned variable from a function to add_shortcode function
- How to add custom content under plugin row in WordPress admin plugin list?
- Create a plugin to change the action to which a function is hooked
- Synchronize Custom post type tags to WordPress default posts tags
- Modifying values with add_action to be sent to db
- Hook to get image filename when it is uploaded
- Which are the hooks run before/after when a category’s deletion?
- Should action callbacks start with a verb?
- Execute Hook on the footer or header after activating a plugin
- WordPress after content Hook & external template part
- best practice for query string values – get_query_var always empty for my value supplied in query string
- get_current_screen() return null
- Adding rewrite rule dynamically
- Get Time Taken By Each Action Hook in WordPress
- How to filter content for specific content variable
- WordPress custom taxonomy check box to dropdown
- I have 2 plugins using the same wp_login action hook and one is not working
- Valid filenames for add_action’s first parameter
- WordPress class, using add_action to call member function does not work
- How dynamic action login_form_{action} is working
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- Bug: Post needs to be updated twice when adding action for save_post hook
- When does save_post hook fire on post save/update
- Remove an action by extending class and replacing it
- hook filter after the_content on a specific page
- Bind a function with its own argument to show something dynamically after every content
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- Update variable value via add_filter
- Configure WordPress to Generate Scheme-less Relative URLs
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- Adding tables to dashboard pages programmatically?
- Action / Hook when a new plugin is added
- Limit get_next_post to posts from the same author
- Any way, hook to add content right before the “read more” link?
- remove different admin menu for specific users
- WordPress Reset password Strength set to medium
- add_option_{$option} action hook not being called
- Does WordPress have something like timer hook?
- How can I set a dynamic value for post_updated_messages based on return value of post_updated?
- How do I replace title with my plugin?
- Insert plugin html content to a specific spot in the frontpage
- How many filter/action hooks are healthy?
- Valid characters for actions, hooks and filters
- Is there widely accepted phpDoc syntax for documenting which hook calls a function?
- WordPress scheduled task is called but not executed
- Display only certain posts based on visitor’s country?
- Odd behaviour with submenu link creation
- Help with callback using do_action_ref_array
- How to allow Unfiltered HTML in a wordpress multisite install
- do_action and hook methods
- Is it possible to add an action to the currently running action?
- How to prevent action in ajax request, when in admin side?
- multiple functions with same filter
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- Filter taxonomy admin pagination
- Search and Filter
- Trying to get class to instantiate ONCE (or, “why do I keep punching myself in the head?”)
- remove_action not removing add_action from constructor
- Remove actions/filters that are set with create_function()
- Use has_filter on comment_post
- Is there an action_filter hook to add content before the post title?
- How to update global variables in plugin activation callback?
- Hook to change the site URL
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- How do I remove an action hook inside a class that is called by another class?
- How wordpress plugin hooks works? [duplicate]
- Send Webhook when post-status is publish or trash
- Using “add_image_size” to register custom image sizes inside plugins not working