I was debugging something in WordPress, trying to figure out what callback function was applying a change to a filter (in this case a post’s content). To get a list of what functions were hooked into the filter, I threw together a quick helper function and I thought I’d post it here incase anyone else found it useful.
[code lang=”php”]function viper_debug_filter( $filter ) {
add_filter( $filter, function( $value ) {
global $wp_filter;
$filters = array();
foreach ( (array) $wp_filter[ current_filter() ] as $priority => $functions ) {
foreach ( (array) $functions as $function => $args ) {
$filters[$priority][] = $function;
}
}
var_dump( current_filter(), $filters );
return $value;
} );
}
// Pass the filter name here
viper_debug_filter( ‘the_content’ );[/code]
Nothing fancy like excluding itself from the output — it was just a quick and dirty hack. Use it as you see fit.
We should ship the Hook Explorer 🙂
Thanks for this, Alex!
I improved on it a little: https://gist.github.com/hgezim/b9f6390120ddc1b586edae941771ece0