Skip to content

Instantly share code, notes, and snippets.

@sabrina-zeidan
Created November 19, 2021 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sabrina-zeidan/64ec89cdd9921017a792db2c55f1ed49 to your computer and use it in GitHub Desktop.
Save sabrina-zeidan/64ec89cdd9921017a792db2c55f1ed49 to your computer and use it in GitHub Desktop.
Display all hooks/actions fired during the current page load [WordPress]
class MyTracker {
static $hooks;
static function track_hooks( ) {
$filter = current_filter();
if ( ! empty($GLOBALS['wp_filter'][$filter]) ) {
foreach ( $GLOBALS['wp_filter'][$filter] as $priority => $tag_hooks ) {
foreach ( $tag_hooks as $hook ) {
if ( is_array($hook['function']) ) {
if ( is_object($hook['function'][0]) ) {
$func = get_class($hook['function'][0]) . '->' . $hook['function'][1];
} elseif ( is_string($hook['function'][0]) ) {
$func = $hook['function'][0] . '::' . $hook['function'][1];
}
} elseif( $hook['function'] instanceof Closure ) {
$func = 'a closure';
} elseif( is_string($hook['function']) ) {
$func = $hook['function'];
}
self::$hooks[] = 'On hook <b>"' . $filter . '"</b> run <b>'. $func . '</b> at priority ' . $priority;
}
}
}
}
}
add_action( 'all', array('MyTracker', 'track_hooks') );
add_action( 'shutdown', function() {
echo implode( '<br />', MyTracker::$hooks );
}, 9999);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment