Is it possible to create an action hook using do_action() within add_action()?

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.

Leave a Comment