0

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?

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

1 Answer 1

4

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
  • 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. Oct 25, 2017 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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