According to docs:

do_action( string $tag, $arg = '' )

Execute functions hooked on a specific action hook.

I have already written plugins. and they have many do_action() function without any functions hooked to that specific hook.

What is the use of do_action( 'wpdocs_i_am_hook'); with wpdocs_i_am_hook used nowhere else?

  • this cas be used by other plugins to do custom actions. – mmm Oct 25 '17 at 9:00

If you are seeing this in plugins (or leaving them in your own) then you are making your plugins more developer friendly.

For example, we can use do_action('stv_plugin_on_form_submit', $entry, $form, $user); inside a custom plugin that tracks form submissions. After all of your code and before the function completes, adding the do_action would enable another developer to extend the functionality of your plugin.

Here's my "extension" to your plugin via the action defined:

add_action('stv_plugin_on_form_submit', 'tom_custom_stv_plugin_on_form_submit');
function tom_custom_stv_plugin_on_form_submit($entry, $form, $user){
    //send HTTP POST to API
}

If you're using this technique, you are ensuring that your plugin (or theme) is more flexible for other to use in the future.

Further reading:

  • 1
    I think an important addendum to this is that basically means that your plugin now has its own API and code is going to depend on these filters and actions having a decent level of stability. – Jacob Peattie Oct 25 '17 at 9:34

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.