List all hooked WordPress functions

June 24, 2009 at 9:26 am

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.

Tags: