
WordPress hooks are very useful because they allow you to “surcharge” an existing WP function with your own code. But when things goes wrong, it should be useful to be able to list all hooked WordPress functions. Here is the code to it.

WordPress hooks are very useful because they allow you to “surcharge” an existing WP function with your own code. But when things goes wrong, it should be useful to be able to list all hooked WordPress functions. Here is the code to it.
The first thing to do is to paste the following function in your functions.php file:
function list_hooked_functions($tag=false){
global $wp_filter;
if ($tag) {
$hook[$tag]=$wp_filter[$tag];
if (!is_array($hook[$tag])) {
trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
return;
}
}
else {
$hook=$wp_filter;
ksort($hook);
}
echo '<pre>';
foreach($hook as $tag => $priority){
echo "<br />>>>>>\t<strong>$tag</strong><br />";
ksort($priority);
foreach($priority as $priority => $function){
echo $priority;
foreach($function as $name => $properties) echo "\t$name<br />";
}
}
echo '</pre>';
return;
}
Once done, simply call the list_hooked_functions() function to print on the screen all hooked WordPress functions. Please note that this function is for debugging purposes only.
list_hooked_functions()
Thanks to Rarst for contributing to WpRecipes with this very useful function! If you'd like to contribute to WpRecipes, don't hesitate to contact me.
21 Responses
You can also list only specific hook with passing its name as attribute:
list_hooked_functions(’wp_head’);
Hope my snippet will be of use to others.
great stuff!.. been looking for something like this
I will try to use it, thanks for sharing nice functions
@Freelance Jobs
You are welcome.
I would love to hear your feedback later – if it was useful and handy.
Wordpress hooks are really useful. I have never had anything go wrong in my experience, but I think this code could be really helpful.
@used tires
It is convenient to add stuff with hooks but much trickier to remove something from them. I am also tinkering with Hybrid framework that has its own set of hooks which makes things confusing at times.
Neat ideea, especially the formatting.
Thanks for sharing!
Nice function ! Thanks
@scribu
Well, I’ve started with single print_r but it was very inconvenient and some info in array is duplicated so most of function is actually spent on convenient output.
+@Thomas
You are welcome.
wprecipes is nice place for sharing such stuff that otherwise gathers dust in snippets.
looks like it is pretty useful. It would be nice if there was a little explanation saying how it works. It is a little mystic and confusing for my newbish PHP skills
@Scott Petrovic
I am quite a newbie in PHP myself, sorry if it’s not clear enough.
Do you have specific questions on function itself? I’ll do my best to answer them.
If you need help on hooks system itself I can only advise to go through official documentation, too much stuff to explain in short:
http://codex.wordpress.org/Plugin_API
Great stuff!.. Thank’s
Excellent reference. Thanks for the useful info.
Thanks.. great reference.. I will try to use it..
Trackbacks: