作为一个例子,我正在看class-wp-xmlrpc-server.php
有一句话(~ 115)说:
$this->methods = apply_filters(\'xmlrpc_methods\', $this->methods);
我如何才能真正找出过滤器对数据执行了哪些转换?显然,我可以比较$this->methods
在应用过滤器前后获得底线差异,但我想知道实际运行的代码是什么来进行这些更改。有什么想法吗?
作为一个例子,我正在看class-wp-xmlrpc-server.php
有一句话(~ 115)说:
$this->methods = apply_filters(\'xmlrpc_methods\', $this->methods);
我如何才能真正找出过滤器对数据执行了哪些转换?显然,我可以比较$this->methods
在应用过滤器前后获得底线差异,但我想知道实际运行的代码是什么来进行这些更改。有什么想法吗?
这里有一个片段,类似于上面的片段,每次调用它时,它都会打印出所有(或指定)钩子的钩子函数。其优点是,这将捕获(更多,而不是全部)“动态”添加的挂钩。特别是,它将仅显示调用时当前挂接到该挂钩上的函数。(有时会删除某个函数或将其添加到特定实例的挂钩中)。另一方面,它需要调用钩子。
该代码段适用于操作和过滤器(它们本质上是相同的东西),但像上面一样,只能为您提供优先级、名称和参数数量。要了解函数本身在做什么,您必须找到它们。。。
用法:以管理员用户身份登录。访问任何页面,无论是正面还是背面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;
}
这将只显示在页面加载过程中激发的挂钩。通过与$wp_filter
全局,您可以查看在任何给定时间设置的所有筛选器。为了节省您的时间,我们自己的@Rarst编写了一些代码,可以为您完成这项工作,您可以找到它here [死链接]。确保在添加过滤器后执行此操作,以便最终不会遗漏任何重要内容。
我正在尝试向侧栏搜索框添加一些复选框选项,similar to this, 用户可以选择是否搜索All Words, Some Word, 或者Entire phrase.我确实在搜索后找到了这个-Wordpress Search Phrases. “句子”选项似乎很有效,但其他选项则不太好。下面的代码是我目前正在处理的,但如果能得到一些帮助使其正常工作,我将不胜感激。非常感谢S(我不想为此使用插件)。<form action=\"<?php bloginfo(\'home\'); ?>