Last active
January 17, 2017 18:26
-
-
Save funkjedi/4ee7b2f9ab31f33977155271865189d2 to your computer and use it in GitHub Desktop.
Display Information About the Registered Actions and Filters in Wordpress
This file contains hidden or 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_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