如何在发送前挂钩联系表格 7 [英] How to hook into Contact Form 7 Before Send

查看:24
本文介绍了如何在发送前挂钩联系表格 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个插件,我想与联系表 7 进行交互.在我的插件中,我添加了以下操作 add_action

I have a plugin I am writing that I want to interact with Contact Form 7. In my plugin I added the following action add_action

add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");

function wpcf7_do_something_else(&$wpcf7_data) {

    // Here is the variable where the data are stored!
    var_dump($wpcf7_data);

    // If you want to skip mailing the data, you can do it...
    $wpcf7_data->skip_mail = true;

}

我提交了联系表格,但我没有做任何添加操作.我不确定如何让我的插件在联系表格 7 时拦截或执行某些操作做某事.任何有关如何执行此操作的帮助?

I submitted the contact form but the add_action I had did nothing. I'm unsure how to make my plugin intercept or do something when Contact Form 7 does something. Any, help on how to do this?

推荐答案

我必须这样做以防止发送电子邮件.希望有帮助.

I had to do this to prevent Email from being sent. Hope it helps.

/*
    Prevent the email sending step for specific form
*/
add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");  
function wpcf7_do_something_else($cf7) {
    // get the contact form object
    $wpcf = WPCF7_ContactForm::get_current();

    // if you wanna check the ID of the Form $wpcf->id

    if (/*Perform check here*/) {
        // If you want to skip mailing the data, you can do it...  
        $wpcf->skip_mail = true;    
    }

    return $wpcf;
}

此代码假设您运行的是最新版本的 CF7,您的上述代码在几个月前开始对代码进行了一些重构之前一直可以工作.[2015 年 4 月 28 日]

This code assumes that you are running the latest version of CF7 your code above used to work until a couple months ago when they went and did some refactoring of the code. [Apr 28 '15]

这篇关于如何在发送前挂钩联系表格 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆