1

Is there a way to check if a custom hook gets called upon? I would like to display a placeholder if no output will be passed to it.

2 Answers 2

4

I believe you are looking for has_action, which should ...

Check if any action has been registered for a hook.

if (has_action('custom_action')) {
  // stuff
} else {
  // different stuff
}
1
  • Hm, okay, so this is what the question really was about... ;)
    – tfrommen
    Commented Feb 19, 2014 at 19:06
2

Do you know did_action?

If I understood you correctly, you are looking for something like the following:

if (0 === did_action('custom_action')) {
    // placeholder, or whatever
}
2
  • 1
    Although did_action() is very useful too it works a little differently than what I was looking for in the end. If I'm correct did_action() counts the amount of time a specific do_action($) has been executed on different locations right?
    – user17235
    Commented Feb 19, 2014 at 19:38
  • Yes, that's right. And that's how I understood your question. Determine if a specific action has been called (until now) and react on that data. has_action() returns true if there is at least one action registered - but it doesn't care if it's already been called or not.
    – tfrommen
    Commented Feb 19, 2014 at 19:49

Your Answer

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