How to check if a hook is hooked or not?

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 Comment