Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 来自变量的Wordpress过滤器?_Php_Wordpress_Function_Add Filter - Fatal编程技术网

Php 来自变量的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

我记不起如何正确地构造它,但我正在尝试更改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_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?