简体   繁体   English

wordpress 联系表 7 禁用电子邮件

[英]wordpress contact form 7 disable email

I am facing an issue with Contact Form 7 for Wordpress .我在Wordpress 的 Contact Form 7 方面遇到了问题。 I want to disable the email notification which i did using我想禁用我使用的电子邮件通知

demo_mode: on

At the same time i want to redirect on submit which i used to do using同时我想重定向我曾经使用的提交

on_sent_ok: "location = 'http://domain.com/about-us/';" 

Both would work when used individually.But i want to use both at the same time.单独使用时两者都可以使用。但我想同时使用两者。

I tried doing我试着做

    on_sent_ok: "location = 'http://domain.com/about-us/';" 
demo_mode: on

Doesnt seem to work.似乎不起作用。 Kindly advice.亲切的建议。

The plugin author has changed as of at least 4.0 the way you should do this again.插件作者至少从 4.0 更改了您应该再次执行此操作的方式。 The skip_mail property is now private : skip_mail属性现在是私有的:

class WPCF7_Submission {
    private $skip_mail = false;
    ...
}

You should use this filter : wpcf7_skip_mail你应该使用这个过滤器: wpcf7_skip_mail

For example :例如:

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');

The author of the plugin Contact Form 7 has refactored some of the code for its version 3.9 and since then the callback function for the hook wpcf7_before_send_mail must be written differently.插件Contact Form 7的作者为其3.9 版重构了一些代码,从那时起,钩子wpcf7_before_send_mail的回调函数必须以不同的方式编写。

To prevent Contact Form 7 from sending the email and force it to redirect after the form has been submitted, please have a look at the following piece of code (for version >= 3.9):为了防止 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//');\"",
    ) );
}

Hook into wpcf7_before_send_mail instead of using the flag .挂钩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;  

    }  

Just an update.只是一个更新。 The following works in 4.1.1.以下在 4.1.1 中工作。

 on_sent_ok: "location = 'http://domain.com/about-us/';" 
 demo_mode: on

There might have been a change to contact-form-7, because I wasn't able to access the $skip_mail variable in the WPCF7_Submission object.可能对 contact-form-7 进行了更改,因为我无法访问 WPCF7_Submission 对象中的 $skip_mail 变量。 I looked at the submission.php object in the \\wp-content\\plugins\\contact-form-7\\includes\\submission.php file and found this:我查看了 \\wp-content\\plugins\\contact-form-7\\includes\\submission.php 文件中的 submit.php 对象,发现了这个:

private $skip_mail = false;

Since the variable is private, and there are no getters or setters in the file, you're not going to be able to change it externally.由于该变量是私有的,并且文件中没有 getter 或 setter,因此您将无法从外部更改它。 Just change it to this:只需将其更改为:

public $skip_mail = false;

and then you can change the variable like this in your functions.php file:然后你可以在你的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;

}

A reminder, if you update the contact-form-7 plugin, it will probably nullify your change, so keep that in mind.提醒一下,如果您更新 contact-form-7 插件,它可能会使您的更改无效,因此请记住这一点。

设置skip_mail: on可以解决问题。

UPDATE WPCF7 ver.更新 WPCF7 版本。 7.5: There is now a filter specifically to handle this. 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');

Simple code简单的代码

Copy and paste the following code in your activated theme functions.php file.将以下代码复制并粘贴到您激活的主题 functions.php 文件中。

add_filter('wpcf7_skip_mail','__return_true');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM