发送前如何挂钩到联系表7 [英] How to hook into Contact Form 7 Before Send
问题描述
我有一个正在编写的插件,希望与联系表单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;
}
我提交了联系表格,但是我没有做的add_action 。
我不确定在联系表格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,上面使用的代码一直工作到几个月前,他们去做代码的重构。 [15年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屋!