Skip to content

Instantly share code, notes, and snippets.

@WPsites WPsites/gist:6083397
Last active Dec 20, 2015

What would you like to do?
Function to inspect WordPress filters/actions that match a regular expression
//hook into the 'shutdown' action and debug some filters... but not on the admin this time
if (! is_admin() )
add_action('shutdown', 'use_debug_filters',10);
function use_debug_filters(){
echo "<h3>Output hooks and filters that contain the string 'init'</h3>";
echo "<h3>Output hooks and filters that contain the string 'before'</h3>";
echo "<h3>Output hooks and filters that start with 'wp'</h3>";
* Loop through $wp_filter array and output any actions/filters that match the regular expression passed in.
function debug_filter($regex_filter_action_to_match = "//"){
global $wp_filter;
echo "<pre style='background-color:white;'>";
foreach($hook as $tag => $priority){
//check for a regex match of hook name
if ( !preg_match($regex_filter_action_to_match, $tag) ) continue;
echo "<br /><strong>$tag</strong><br />";
foreach($priority as $priority => $function){
echo " $priority \n";
foreach($function as $name => $properties) {
echo "\t$name ";
if ( function_exists($name) ){
$func = new ReflectionFunction($name);
$filename = $func->getFileName();
$start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
$path_info = pathinfo($filename);
echo "<em style='font-size:90%;opacity:0.5;' title='{$filename}'> {$path_info[filename]}.{$path_info[extension]}: line {$start_line}</em>";
echo "<br />";
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.