Do I need to call do_action
function every time I add_action
something?
Leave a Reply
You must be logged in to post a comment.
Do I need to call do_action
function every time I add_action
something?
You must be logged in to post a comment.
Usually, you use existing action in your plugins. WordPress will call
do_action()
when needed.If your plugin is rather complex, like a shopping plugin, you may want to offer additional actions for other plugin developers or for the pro-version of your plugin. In these cases you add
do_action()
wherever you think it could be useful.An example: I have a library of PHP classes that I use for some projects. When I write a plugin that relies on my library I have to wait until the library is ready. So I write in my library:
In my other plugin I hook into this action to start all the work:
Now I know all needed classes available, I donât have to test
class_exists()
each time.add_action()
anddo_action()
are not necessary tied together. So the answer to your question is: no. 🙂