Find all functions hooking into an action or filter

Posted by & filed under Wordpress.

Thanks to Jon Bishop for this one:

function amp_find_filters($filter_name) {
    global $wp_filter;
    echo 'Filter: ' . $filter_name . '<br>';
    if (isset($wp_filter[$filter_name])) {
        foreach ($wp_filter[$filter_name] as $priority => $functions) {
            foreach ($functions as $function => $args) {
                if (is_object($args['function'][0])) {
                    $refClass = new ReflectionClass($args['function'][0]);
                    $refFunc = $refClass->getMethod($args['function'][1]);
                    echo 'class name: ' . $refClass->getName() . '<br>';
                    echo 'method name: ' . $args['function'][1] . '<br>';
                } else {
                    $refFunc = new ReflectionFunction($args['function']);
                    echo 'function name: ' . $args['function'] . '<br>';
                }
                echo 'file name: ' . $refFunc->getFileName() . '<br>';
                echo 'start line: ' . $refFunc->getStartLine() . '<br>';
                echo '<hr>';
                $refFunc = null;
            }
        }
    }
}
amp_find_filters('wp_footer');

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Bitnami