All functions that are hooked onto an action are automatically executed IF that action is called, but they are not called if the action is not triggered.
For example if you have:
add_action("action_one","some_function",10);
Then some_function
will be called if action_one
is triggered. If action_one
is never triggered, some_function is not called.
do_action
is a mechanism to manually trigger the action, though keep in mind it will trigger ANY hooks into that action, not just yours (unless you setup some filters).
Another example: let's say you setup a custom function to run on the action save_post
:
add_action( 'save_post', 'top_secret_function' );
Then every time you a save a post your top_secret_function
will run.
If you want to trigger save_post
manually (without actually saving a post) you can do so with:
do_action( 'save_post' );
and it will trigger your top_secret_function
, but this would generally not be recommended because it will also trigger any other function that is hooked into save_post
(which many plugins and core files do).
You can setup custom actions using a combination of add_action
and do_action
.