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
1

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

Leave a Reply

Your email address will not be published. Required fields are marked *