Last active
October 3, 2024 17:17
-
-
Save wvega/465c7854712fe29b3c7e16f5bbc40222 to your computer and use it in GitHub Desktop.
Utility functions for debugging WordPress websites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ( $handler['function'] instanceof Closure ) { | |
$function = new ReflectionFunction( $handler['function'] ); | |
$hook_handlers[] = array( | |
'priority' => $priority, | |
'handler' => 'Closure', | |
'file' => $function->getFileName(), | |
'line' => $function->getStartLine(), | |
); | |
} elseif ( is_string( $handler['function'] ) && 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