Created
August 23, 2013 09:13
-
-
Save ErikBernskiold/6317193 to your computer and use it in GitHub Desktop.
WordPress: List all hooks for a filter/action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dump_hook( $tag, $hook ) { | |
ksort($hook); | |
echo "<pre>>>>>>\t$tag<br>"; | |
foreach( $hook as $priority => $functions ) { | |
echo $priority; | |
foreach( $functions as $function ) | |
if( $function['function'] != 'list_hook_details' ) { | |
echo "\t"; | |
if( is_string( $function['function'] ) ) | |
echo $function['function']; | |
elseif( is_string( $function['function'][0] ) ) | |
echo $function['function'][0] . ' -> ' . $function['function'][1]; | |
elseif( is_object( $function['function'][0] ) ) | |
echo "(object) " . get_class( $function['function'][0] ) . ' -> ' . $function['function'][1]; | |
else | |
print_r($function); | |
echo ' (' . $function['accepted_args'] . ') <br>'; | |
} | |
} | |
echo '</pre>'; | |
} | |
function list_hooks( $filter = false ){ | |
global $wp_filter; | |
$hooks = $wp_filter; | |
ksort( $hooks ); | |
foreach( $hooks as $tag => $hook ) | |
if ( false === $filter || false !== strpos( $tag, $filter ) ) | |
dump_hook($tag, $hook); | |
} | |
// Output the hooks. Leave the filter blank and it outputs all hooks. | |
list_hooks( $filter ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment