Skip to content

Instantly share code, notes, and snippets.

@wvega
Last active April 7, 2018 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wvega/465c7854712fe29b3c7e16f5bbc40222 to your computer and use it in GitHub Desktop.
Save wvega/465c7854712fe29b3c7e16f5bbc40222 to your computer and use it in GitHub Desktop.
Utility functions for debugging WordPress websites
<?php
function wp_debug_util_get_hook_handlers( $hook_name ) {
global $wp_filter;
$hook_handlers = array();
foreach ( $wp_filter[ $hook_name ] as $priority => $handlers ) {
foreach ( $handlers as $handler ) {
if ( is_array( $handler['function'] ) && is_callable( $handler['function'] ) && is_object( $handler['function'][0] ) ) {
$class = new ReflectionClass( get_class( $handler['function'][0] ) );
$method = new ReflectionMethod( $class->getName(), $handler['function'][1] );
$hook_handlers[] = array(
'priority' => $priority,
'handler' => $class->getName() . ( $method->isStatic() ? '::' : '->' ) . $method->getName(),
'file' => $class->getFileName(),
'line' => $method->getStartLine(),
);
} elseif ( is_array( $handler['function'] ) && is_callable( $handler['function'] ) && is_string( $handler['function'][0] ) ) {
$class = new ReflectionClass( $handler['function'][0] );
$method = new ReflectionMethod( $class->getName(), $handler['function'][1] );
$hook_handlers[] = array(
'priority' => $priority,
'handler' => $class->getName() . ( $method->isStatic() ? '::' : '->' ) . $method->getName(),
'file' => $class->getFileName(),
'line' => $method->getStartLine(),
);
} elseif ( function_exists( $handler['function'] ) ) {
$function = new ReflectionFunction( $handler['function'] );
$hook_handlers[] = array(
'priority' => $priority,
'handler' => $handler['function'],
'file' => $function->getFileName(),
'line' => $function->getStartLine(),
);
} else {
$hook_handlers[] = array(
'handler' => $handler['function'],
);
}
}
}
return $hook_handlers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment