6

For example:

if ( is_hooked('hook_name') ) {
  throw new \Exception('You cannot hook to a protected action.');
} else {
  do_action('hook_name');
}

Is there a way to define the is_hooked() function?

1 Answer 1

4

Sure, that's called has_action, which is an alias of has_filter. Usage:

if ( has_action('hook_name') ) {
  throw new \Exception('You cannot hook to a protected action.');
} else {
  do_action('hook_name');
}

These two functions access the global array $wp_filter that stores all of the filters / actions

0

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.