【发布时间】:2020-04-06 02:06:59
【问题描述】:
这是我第一次尝试向我的functions.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_array 感到困惑。我该怎么办?我真的只想覆盖 $form_settings 数组中的 form_to。我会很感激任何提示!非常感谢!
【问题讨论】: