Post Pic

List all hooked WordPress functions

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 />&gt;&gt;&gt;&gt;&gt;\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.

Related Posts

21 Responses

Jun 24 2009 10:30

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. :)

Jun 24 2009 11:43

great stuff!.. been looking for something like this

Jun 24 2009 15:18

I will try to use it, thanks for sharing nice functions

Jun 24 2009 15:55

@Freelance Jobs

You are welcome. :) I would love to hear your feedback later – if it was useful and handy.

Jun 24 2009 20:34

Wordpress hooks are really useful. I have never had anything go wrong in my experience, but I think this code could be really helpful.

Jun 25 2009 07:17

@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.

Jun 25 2009 14:02

Neat ideea, especially the formatting.

Thanks for sharing! :)

Jun 25 2009 19:22

Nice function ! Thanks

Jun 25 2009 19:58

@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.

Jun 30 2009 16:00

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

Jun 30 2009 17:03

@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

Jul 10 2009 01:34

Great stuff!.. Thank’s

Jul 11 2009 03:54

Excellent reference. Thanks for the useful info.

Aug 07 2009 10:06

Thanks.. great reference.. I will try to use it..

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required