Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to know what functions are hooked to a particular hook? For example if I'd like to know what functions are hooked to the wp_head hook.

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

I'm pretty sure that this does what you want:

@Rarst's Debug WordPress hooks

share|improve this answer
    
great thanks!!! –  javiervd May 16 '11 at 16:13
add comment

Look into the global variable $wp_filter. See my plugin for a list of all comment filters for an example:

<?php
/*
Plugin Name: List Comment Filters
Description: List all comment filters on wp_footer
Version:     1.1
Author:      Thomas Scholz
Author URI:  http://toscho.de
License:     GPL v2
*/

add_action( 'wp_footer', 'list_comment_filters' );

function list_comment_filters()
{
    global $wp_filter;

    $comment_filters = array ();
    $h1  = '<h1>Current Comment Filters</h1>';
    $out = '';
    $toc = '<ul>';

    foreach ( $wp_filter as $key => $val )
    {
        if ( FALSE !== strpos( $key, 'comment' ) )
        {
            $comment_filters[$key][] = var_export( $val, TRUE );
        }
    }

    foreach ( $comment_filters as $name => $arr_vals )
    {
        $out .= "<h2 id=$name>$name</h2><pre>" . implode( "\n\n", $arr_vals ) . '</pre>';
        $toc .= "<li><a href='#$name'>$name</a></li>";
    }

    print "$h1$toc</ul>$out";
}

Sample output for pre_comment_author_email:

array (
  10 => 
  array (
    'trim' => 
    array (
      'function' => 'trim',
      'accepted_args' => 1,
    ),
    'sanitize_email' => 
    array (
      'function' => 'sanitize_email',
      'accepted_args' => 1,
    ),
    'wp_filter_kses' => 
    array (
      'function' => 'wp_filter_kses',
      'accepted_args' => 1,
    ),
  ),
)
share|improve this answer
    
Great little function toscho, thanks for sharing this. I'm using it to evaluate all of the action hooks loaded for a theme at the shutdown action. –  Kevin Leary Feb 22 '12 at 16:01
add comment

take a look at this answer to a similar question and more specifically the plugin posted there by mike.

share|improve this answer
    
I could be wrong, but doesn't that just produce a comprehensive list of hooks? The way I'm reading the question is the he wants to know what functions are attached to the hook. –  anu May 16 '11 at 14:37
    
Partially wrong, he said "for example what's hooked to wp_head", so its a full list not only a single hook. –  Bainternet May 16 '11 at 15:21
    
Indeed, I wanted to see what functions are attached to a particular hook, so for example if 10 functions are hooked to wp_head then I'd like to list those 10. –  javiervd May 16 '11 at 16:13
    
well that plugin will list all functions that are hooked with there hook. –  Bainternet May 16 '11 at 16:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.