Skip to content

Instantly share code, notes, and snippets.

@TruongTuyen
Last active April 21, 2017 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TruongTuyen/26190800216d99cb3f512ff87bfcc4d2 to your computer and use it in GitHub Desktop.
Save TruongTuyen/26190800216d99cb3f512ff87bfcc4d2 to your computer and use it in GitHub Desktop.
<?php
function wptq_hooked_action_for( $hook_name = '' ){
global $wp_filter;
if( empty( $hook_name ) || !isset( $wp_filter[$hook_name] ) || !is_object( $wp_filter[$hook_name] ) ){
return;
}
$list_hooked = array();
$callbacks = $wp_filter[$hook_name]->callbacks;
if( !empty( $callbacks ) ){
foreach( $callbacks as $key=>$value ){
if( is_array( $value ) && !empty( $value ) ){
foreach( $value as $k=>$v ){
if( array_key_exists( 'function', $v ) && !is_array( $v['function'] ) ){
$list_hooked[] = array(
'type' => 'function',
'function_name' => $v['function'],
'accepted_args' => $v['accepted_args'],
'priority' => $key
);
}elseif( array_key_exists( 'function', $v ) && is_array( $v['function'] ) && is_object( $v['function'][0] ) && !empty( $v['function'][1] ) ){
$list_hooked[] = array(
'type' => 'method',
'object_name' => get_class( $v['function'][0]),
'method_name' => $v['function'][1],
'accepted_args' => $v['accepted_args'],
'priority' => $key
);
}
}
}
}
}
echo "<pre>";
print_r( $list_hooked );
echo "</pre>";
}
//Example
wptq_hooked_action_for( 'wp_head' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment