我有一个插件,我正在写,我想与联系人表单7交互。在我的插件中,我添加了以下操作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什么也没做。当Contact Form 7做了一些事情时,我不确定如何让我的插件截获或做一些事情。有没有人能帮我解决这个问题?
发布于 2015-09-28 19:54:11
我想补充的是,您可以只使用wpcf7_skip_mail
过滤器:
add_filter( 'wpcf7_skip_mail', 'maybe_skip_mail', 10, 2 );
function maybe_skip_mail( $skip_mail, $contact_form ) {
if( /* your condition */ )
$skip_mail = true;
return $skip_mail;
}
发布于 2020-09-30 09:05:41
从WPCF7 5.2开始,wpcf7_before_send_mail
钩子发生了很大的变化。作为参考,下面是如何在5.2+中使用这个钩子
跳过邮件
function my_skip_mail() {
return true; // true skips sending the email
}
add_filter('wpcf7_skip_mail','my_skip_mail');
或者将skip_mail
添加到管理区域中表单的其他设置选项卡中。
获取表单ID或帖子ID
function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
$post_id = $submission->get_meta('container_post_id');
$form_id = $contact_form->id();
// do something
return $contact_form;
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );
获取用户输入的数据
function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
$your_name = $submission->get_posted_data('your-field-name');
// do something
return $contact_form;
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );
将电子邮件发送给动态收件人
function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
$dynamic_email = 'email@email.com'; // get your email address...
$properties = $contact_form->get_properties();
$properties['mail']['recipient'] = $dynamic_email;
$contact_form->set_properties($properties);
return $contact_form;
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );
https://stackoverflow.com/questions/29926252
复制相似问题