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 any way to know what functions are added to actions on a certain page in WordPress?

share|improve this question
add comment

3 Answers

There is a magic action all which is called on every action or filter. You can hook into this action and log all associated functions. In $GLOBALS['wp_filter'] which you can inspect too you can find all active hooks, eg. hooks that are actually used.

I have written a small plugin T5 Debug Hook to see all functions for one hook:

<?php # -*- coding: utf-8 -*-
/**
 * Plugin Name: T5 Debug Hook
 * Description: Adds a list of registered filters and action for a hook. Call a page with <code>?hook=NAME</code> to see it.
 */

add_action( 'shutdown', 't5_debug_hook' );

function t5_debug_hook()
{
    if ( ! isset ( $_GET['hook'] ) or ! current_user_can( 'update_core') )
    {
        return;
    }

    $f = $GLOBALS['wp_filter'];

    if ( ! isset ( $f[ $_GET['hook'] ] ) )
    {
        print 'Nothing found for ' . esc_html( $_GET['hook'] );
        return;
    }

    print '<pre>' . esc_html( var_export( $f[ $_GET['hook'] ], TRUE ) ) . '</pre>';
}

To get a list of all available actions on a page try this:

<?php # -*- coding: utf-8 -*-
/*
Plugin Name: All Actions List
Description: Lists all actions run during one request.
Version:     1.0
Required:    3.1
Author:      Thomas Scholz
Author URI:  http://toscho.de
License:     GPL
*/
! defined( 'ABSPATH' ) and exit;

add_action( 'all', 'aal_handler', 99999, 99 );

function aal_handler()
{
    static $list = array ();
    // exclude certain actions:
    $exclude = array ( 'gettext', 'gettext_with_context' );

    $action = current_filter();

    if ( ! in_array( $action, $exclude ) )
    {
        $list[] = $action;
    }

    // shutdown is the last action
    if ( 'shutdown' == $action )
    {
        print '<pre>' . implode( "\n", $list ) . '</pre>';
    }
}
share|improve this answer
add comment

WordPress holds current state of hook information in global $wp_filter variable, which you can examine (for example by var_dump()). Note that this is built in runtime, so it doesn't know what is added to hook until after the point in code when that something is added.

There is some helper code floating around, mine is R_Debug::list_hooks().

share|improve this answer
add comment

As Rarst has pointed out, when callbacks are hooked onto actions/filters they are added to the $wp_filter global. Inspecting that allows you to see which functions have been added to that hook (which may be different each time the hook is fired).

See my answer to this question. Or the GitHub gist that resulted from it.

Alternatively you might like to use this plug-in, which adds a search to the admin bar of admin users, that allows you to search for hooks that have been called on that page. Selecting a hook displays a dialog with functions that have were hooked onto that action/filter:

sh-hook-debug screenshot

share|improve this answer
    
Unfortunately doesn't work anymore. –  Julian Mar 10 at 11:37
    
It might not do :( - I've stopped using it and instead use QueryMonitor. It should still work "in principle" however as how are hooks are handled has not changed. –  Stephen Harris Mar 10 at 15:39
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.