[英]wordpress contact form 7 disable email
我在Wordpress 的 Contact Form 7 方面遇到了問題。 我想禁用我使用的電子郵件通知
demo_mode: on
同時我想重定向我曾經使用的提交
on_sent_ok: "location = 'http://domain.com/about-us/';"
單獨使用時兩者都可以使用。但我想同時使用兩者。
我試着做
on_sent_ok: "location = 'http://domain.com/about-us/';"
demo_mode: on
似乎不起作用。 親切的建議。
插件作者至少從 4.0 更改了您應該再次執行此操作的方式。 skip_mail
屬性現在是私有的:
class WPCF7_Submission {
private $skip_mail = false;
...
}
你應該使用這個過濾器: wpcf7_skip_mail
例如:
function my_skip_mail($f){
$submission = WPCF7_Submission::get_instance();
if(/* YOUR TEST HERE */){
return true; // DO NOT SEND E-MAIL
}
}
add_filter('wpcf7_skip_mail','my_skip_mail');
插件Contact Form 7
的作者為其3.9 版重構了一些代碼,從那時起,鈎子wpcf7_before_send_mail
的回調函數必須以不同的方式編寫。
為了防止 Contact Form 7 發送電子郵件並在提交表單后強制其重定向,請查看以下代碼(版本 >= 3.9):
add_action( 'wpcf7_before_send_mail', wpcf7_disablEmailAndRedirect );
function wpcf7_disablEmailAndRedirect( $cf7 ) {
// get the contact form object
$wpcf7 = WPCF7_ContactForm::get_current();
// do not send the email
$wpcf7->skip_mail = true;
// redirect after the form has been submitted
$wpcf7->set_properties( array(
'additional_settings' => "on_sent_ok: \"location.replace('http://example.com//');\"",
) );
}
掛鈎wpcf7_before_send_mail
而不是使用 flag 。
add_action("wpcf7_before_send_mail", "wpcf7_disablemail");
function wpcf7_disablemail(&$wpcf7_data) {
// this is just to show you $wpcf7_data and see all the stored data ..!
var_dump($wpcf7_data); // disable this line
// If you want to skip mailing the data..
$wpcf7_data->skip_mail = true;
}
只是一個更新。 以下在 4.1.1 中工作。
on_sent_ok: "location = 'http://domain.com/about-us/';"
demo_mode: on
可能對 contact-form-7 進行了更改,因為我無法訪問 WPCF7_Submission 對象中的 $skip_mail 變量。 我查看了 \\wp-content\\plugins\\contact-form-7\\includes\\submission.php 文件中的 submit.php 對象,發現了這個:
private $skip_mail = false;
由於該變量是私有的,並且文件中沒有 getter 或 setter,因此您將無法從外部更改它。 只需將其更改為:
public $skip_mail = false;
然后你可以在你的functions.php文件中像這樣更改變量:
add_filter('wpcf7_before_send_mail', 'wpcf7_custom_form_action_url');
function wpcf7_custom_form_action_url( $form)
{
$submission = WPCF7_Submission::get_instance();
$submission->skip_mail = true;
}
提醒一下,如果您更新 contact-form-7 插件,它可能會使您的更改無效,因此請記住這一點。
設置skip_mail: on
可以解決問題。
更新 WPCF7 版本。 7.5:現在有一個專門處理這個問題的過濾器。
function my_skip_mail($f){
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
if (/* do your testing here*/){
return true; // DO NOT SEND E-MAIL
}
}
add_filter('wpcf7_skip_mail','my_skip_mail');
簡單的代碼
將以下代碼復制並粘貼到您激活的主題 functions.php 文件中。
add_filter('wpcf7_skip_mail','__return_true');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.