20

I'm working with the admin bar and trying to debug some of the menus and their priorities.

I know several callbacks get bound to actions, such as this one:

add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );

How can I see what is lined up to be called when a hook like admin_bar_menu is called?

2
  • Hook onto the shutdown action and print the $wp_filters global or similar? .. not got a working WP install right now to say in absolution... (but i know there's a global with filters and/or actions).. just a pointer.. ;)
    – t31os
    Nov 29, 2011 at 22:56
  • awesome - just it needs to be singular $wp_filter
    – cwd
    Nov 30, 2011 at 4:02

2 Answers 2

35

You can see the detailed list of the hook using this snippet:

$hook_name = 'admin_bar_menu';
global $wp_filter;
var_dump( $wp_filter[$hook_name] );
6
  • almost right. needs to be $wp_filter singular. thanks.
    – cwd
    Nov 30, 2011 at 4:02
  • Right, answer updated.
    – Anh Tran
    Dec 1, 2011 at 3:56
  • Is there an easy place that this can be placed so that it can be tested? I realize that this is pretty old, but anyone?
    – derickito
    Jan 31, 2013 at 23:55
  • 1
    You can put it in header or footer, using wp_head, wp_footer or shutdown hook. Note: if you don't want users to see this debug information, you should check user permission by if ( current_user_can( 'manage_options' ) ) {...}
    – Anh Tran
    Feb 1, 2013 at 2:03
  • I use some functions to format it more nicely. Useful if you use it often for debugging and want to see the info quicker. Here is a gist.
    – J.D.
    Jun 6, 2014 at 15:01
0

A list of callback functions:

// list call back functions
    $hook_name = 'admin_bar_menu';
    global $wp_filter;
    echo '<h2>  Hook name: '.  $hook_name . '</h2> ';
    if( isset( $wp_filter[$hook_name]->callbacks )){
        if (is_array($wp_filter[$hook_name]->callbacks )){
        echo '<h2>callback functions > accepted_args </h2>';
            foreach(  $wp_filter[$hook_name]->callbacks as $item){
                if ( is_array( $item)){
                    foreach ( $item as $subitem){
                        echo '<P>'.  $subitem['function'].' '.$subitem['accepted_args'] . '</P>';
                    }
                    
                }
            }
    }}

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