Php 来自变量的Wordpress过滤器?
我记不起如何正确地构造它,但我正在尝试更改Wordpress站点中的Php 来自变量的Wordpress过滤器?,php,wordpress,function,add-filter,Php,Wordpress,Function,Add Filter,我记不起如何正确地构造它,但我正在尝试更改Wordpress站点中的get\u选项设置的输出。我可以正确地获得变量输出,但我记不起需要做什么来过滤输出并在apply\u filters函数中更新 到目前为止,我得到的是: $tab_pos = get_option('tab-items'); add_filter($tab_pos['position'], 'tab_filter'); function new_tab_pos(){ return 'right'; } apply_fil
get\u选项
设置的输出。我可以正确地获得变量输出,但我记不起需要做什么来过滤输出并在apply\u filters
函数中更新
到目前为止,我得到的是:
$tab_pos = get_option('tab-items');
add_filter($tab_pos['position'], 'tab_filter');
function new_tab_pos(){
return 'right';
}
apply_filters('tab_filter', 'new_tab_pos');
基本上,
$tab_pos['position']
正在返回left
,我想将其更改为right
,但我不记得让它挂接到该位置以进行更新。我也不确定是否需要用str\u replace
或类似的东西来更新它。看起来您的参数和函数使用方法有误。。。我想你想要的是这样的东西:
<?php
$tab_pos = get_option('tab-items');
$tab_pos['position'] = apply_filters('tab_filter', $tab_pos['position']);
function new_tab_pos($position){
return 'right';
}
add_filter('tab_filter', 'new_tab_pos', 10, 1);
嗯,我试过了,但没有任何效果。我知道
tab items
返回时带有某种类型的数据数组,我正试图定位其中的位置,这就是为什么我有$tab_pos['position']
的原因,因此我可以获得left
的默认值,然后将其更改为right
,我已经编辑过,但这仍然未经测试。不过,我想用这个答案说明的要点是,您使用了add_filter和apply_filters。参数对他们来说也是不正确的。我不明白你想在这里实现什么。是否要将get\u选项('tab-items')
值更改为返回right而不是left?