23 December 2013

List All Hooked 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();

No comments:

Post a Comment