这里有一个片段,类似于上面的片段,每次调用它时,它都会打印出所有(或指定)钩子的钩子函数。其优点是,这将捕获(更多,而不是全部)“动态”添加的挂钩。特别是,它将仅显示调用时当前挂接到该挂钩上的函数。(有时会删除某个函数或将其添加到特定实例的挂钩中)。另一方面,它需要调用钩子。
该代码段适用于操作和过滤器(它们本质上是相同的东西),但像上面一样,只能为您提供优先级、名称和参数数量。要了解函数本身在做什么,您必须找到它们。。。
用法:以管理员用户身份登录。访问任何页面,无论是正面还是背面GET
参数设置为debug=secret
和(可选)hook=hook_name
.
This snippet is for development only.
if( current_user_can(\'administrator\') && !empty($_GET[ \'debug\' ]) && \'secret\' == $_GET[ \'debug\' ] ){
global $sh_fired_filters;
$sh_fired_filters = array();
add_action(\'all\',\'store_fired_filters\');
add_action( \'shutdown\' , \'display_fired_filters\' );
}
function store_fired_filters($tag){
if(!empty($_GET[ \'hook\' ]) && $_GET[ \'hook\' ]!= $tag)
return;
global $wp_filter;
global $sh_fired_filters;
if( ! isset($wp_filter[$tag]))
return;
$hooked = $wp_filter[$tag];
ksort($hooked);
foreach ($hooked as $priority => $function):
$hooked[] = $function;
endforeach;
$sh_fired_filters[] = array(\'tag\'=>$tag, \'hooked\' => $wp_filter[$tag]);
}
function display_fired_filters(){
global $sh_fired_filters;
global $wp_filter;
foreach($sh_fired_filters as $index=> $the_):
echo "<h1>".$index.\' \'.$the_[\'tag\']."</h1>";
echo "<ul>";
foreach($the_[\'hooked\'] as $priority => $hooked):
foreach($hooked as $id => $function):
echo \'<li>\'.$priority.\' <strong>\'.print_r($function[\'function\'],true).\'</strong> (accepted args:\'.$function[\'accepted_args\'].\')</li>\';
endforeach;
endforeach;
echo "</ul>";
endforeach;
}
这将只显示在页面加载过程中激发的挂钩。