Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wordpress contact form 7 disable email

Tags:

php

wordpress

I am facing an issue with Contact Form 7 for Wordpress. 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.

like image 781
user1411837 Avatar asked Dec 01 '22 02:12

user1411837


2 Answers

The plugin author has changed as of at least 4.0 the way you should do this again. The skip_mail property is now private :

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

You should use this filter : 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');
like image 55
Armel Larcier Avatar answered Dec 05 '22 16:12

Armel Larcier


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.

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):

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//');\"",
    ) );
}
like image 44
Mike Avatar answered Dec 05 '22 17:12

Mike