5

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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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