Skip to content

Instantly share code, notes, and snippets.

@funkjedi
Last active January 17, 2017 18:26
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 funkjedi/4ee7b2f9ab31f33977155271865189d2 to your computer and use it in GitHub Desktop.
Save funkjedi/4ee7b2f9ab31f33977155271865189d2 to your computer and use it in GitHub Desktop.
Display Information About the Registered Actions and Filters in Wordpress
<?php
function wp_filter_dump($name) {
global $wp_filter;
$handlers = array();
if (!isset($wp_filter[$name])) {
return $handlers;
}
foreach ($wp_filter[$name] as $priority => $callbacks) {
foreach ($callbacks as $callback) {
$handler = array(
'function' => null,
'priority' => $priority,
'accepted_args' => $callback['accepted_args'],
'file' => null,
'line' => null,
'error' => null,
);
try {
// Handle static functions
if (is_string($callback['function']) && strpos($callback['function'], '::')) {
$handler['function'] = $callback['function'];
$ref = new \ReflectionClass(strstr($callback['function'], '::', true));
$handler['file'] = $ref->getFileName();
try {
$handler['line'] = $ref->getMethod(substr($callback['function'], strpos($callback['function'], '::') + 2))->getStartLine();
}
catch (\ReflectionException $e) {
$handler['error'] = $e->getMessage();
}
}
// Handle functions
elseif (is_string($callback['function'])) {
$handler['function'] = $callback['function'];
$ref = new \ReflectionFunction($callback['function']);
$handler['file'] = $ref->getFileName();
$handler['line'] = $ref->getStartLine();
}
// Handle methods
elseif (is_array($callback['function'])) {
$ref = new \ReflectionClass($callback['function'][0]);
$handler['function'] = $callback['function'];
if (is_object($callback['function'][0])) {
$handler['function'][0] = get_class($handler['function'][0]);
}
$handler['function'] = 'array('.implode(',',$handler['function']).')';
$handler['file'] = $ref->getFileName();
try {
if (strpos($callback['function'][1], 'parent::')) {
$handler['line'] = $ref->getParentClass()->getMethod(substr($callback['function'][1], strpos($callback['function'][1], '::') + 2))->getStartLine();
} else {
$handler['line'] = $ref->getMethod($callback['function'][1])->getStartLine();
}
}
catch (\ReflectionException $e) {
$handler['error'] = $e->getMessage();
}
}
// Handle closures
elseif (is_a($callback['function'], 'Closure')) {
$handler['function'] = get_class($callback['function']);
$ref = new \ReflectionFunction($callback['function']);
$handler['file'] = $ref->getFileName();
$handler['line'] = $ref->getStartLine();
}
// Handle unrecognized
else {
$handler['error'] = 'Handler has an unrecognized callable signature.';
}
}
catch (\ReflectionException $e) {
$handler['error'] = $e->getMessage();
}
$handlers[] = $handler;
}
}
return $handlers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment