Wordpress过滤器,更改插件阵列

Wordpress过滤器,更改插件阵列,wordpress,forms,filter,Wordpress,Forms,Filter,这是我第一次尝试在myfunctions.php中添加过滤器。我试图覆盖插件设置的表单设置,这取决于使用的表单或查看的页面 我试图覆盖的数组在插件中如下所示: $form_settings = (object) array( 'form_title' => stripslashes( html_entity_decode( $form->form_title, ENT_QUOTES, 'UTF-8' ) ),

这是我第一次尝试在myfunctions.php中添加过滤器。我试图覆盖插件设置的表单设置,这取决于使用的表单或查看的页面

我试图覆盖的数组在插件中如下所示:

$form_settings = (object) array(
            'form_title'                    => stripslashes( html_entity_decode( $form->form_title, ENT_QUOTES, 'UTF-8' ) ),
            'form_subject'                  => stripslashes( html_entity_decode( $form->form_email_subject, ENT_QUOTES, 'UTF-8' ) ),
            'form_to'                       => ( is_array( unserialize( $form->form_email_to ) ) ) ? unserialize( $form->form_email_to ) : explode( ',', unserialize( $form->form_email_to ) ),
            'form_from'                     => stripslashes( $form->form_email_from ),
            'form_from_name'                => stripslashes( $form->form_email_from_name ),
            'form_notification_setting'     => stripslashes( $form->form_notification_setting ),
            'form_notification_email_name'  => stripslashes( $form->form_notification_email_name ),
            'form_notification_email_from'  => stripslashes( $form->form_notification_email_from ),
            'form_notification_subject'     => stripslashes( html_entity_decode( $form->form_notification_subject, ENT_QUOTES, 'UTF-8' ) ),
            'form_notification_message'     => stripslashes( $form->form_notification_message ),
            'form_notification_entry'       => stripslashes( $form->form_notification_entry )
        );
        // Allow the form settings to be filtered (ex: return $form_settings->'form_title' = 'Hello World';)
        $form_settings = (object) apply_filters_ref_array( 'vfb_email_form_settings', array( $form_settings, $form_id ) );

我的functions.php看起来像

function maildeponselectcountry() {
    //here comes the new mailadress 
    $form_id = 2;

    $form_settings = array(
        "form_title" => "test"
    );

    apply_filters_ref_array( 'vfb_email_form_settings', array( $form_settings, $form_id ) );

}

apply_filters( 'vfb_email_form_settings', 'maildeponselectcountry' );

我被apply_filters_ref_数组搞糊涂了。那我该怎么办?我只想覆盖$form\u设置数组中的form\u to。如果有任何提示,我将不胜感激!非常感谢你

您不需要使用
应用过滤器\u ref\u数组
。这就是插件允许您使用过滤器的地方。您还需要使用
add\u filter
而不是
apply\u filter
<代码>应用过滤器用于设置允许过滤的数据

您的函数应该如下所示:

function maildeponselectcountry( array( $form_settings, $form_id ) ) {

    /* not sure what is actually passed here, 
       but if you need to check for the form_id, 
       it might be something like this. The passed array is actually an object 
       because of typecasting. */

    if ( $form_id->id == 2 ) {
       // Set the object property value
       $form_settings->form_title = 'test';
    }

    // return the form_settings with or without the updated value (depending on the form_id)
    return $form_settings;
}

// Use add_filter and set the priority.
add_filter( 'vfb_email_form_settings', 'maildeponselectcountry', 10 );
编辑:

尝试运行此测试:

function maildeponselectcountry( $form_settings ) {

       return $form_settings->form_title = 'Test';
    }

    // Use add_filter and set the priority.
    add_filter( 'vfb_email_form_settings', 'maildeponselectcountry', 10 );

运行时,请发布“”的输出,以便我们可以看到返回的数据。

噢,哇,非常感谢!这部分功能“MaildeSelectCountry(array($form\u settings,$form\u id)){`似乎有问题。它创建了一个服务器错误,表示页面有问题。当我移除数组时,网页再次工作。错误是什么?另外,您可能只需传递
$form\u settings
,而不是
数组($form\u settings,$form\u id)
。我没有你的确切插件,所以测试有点困难。是的,我只尝试了函数maildeponselectcountry($form\u settings){这正在工作。但它不会覆盖数组。该插件是Visual Form Builder。免费版本确实运行了您的测试。它没有给出错误,但如何查看它是否添加了“我看不到”的前端。测试回音是这样的:'stdClass对象([Form_title]=>Kontaktformular[Form_subject]=>Kontaktformular…[Form_to]=>数组([0]=>test@test.ch)[表格从]=>test@test.ch[form\u from\u name]=>ORELL-Tec[form\u notification\u setting]=>[form\u notification\u email\u name]=>[form\u notification\u email\u from]=>[form\u notification\u subject]=>[form\u notification\u message]=>[form\u notification\u entry]=>)'