Nat*_*ade 11 wordpress wordpress-plugin contact-form-7
我有一个插件,我写的是我想与Contact Form 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;
}
Run Code Online (Sandbox Code Playgroud)
我提交了联系表单,但add_action我没有做任何事情.我不确定如何使用插件拦截或在联系表单7执行某些操作时执行某些操作.任何,帮助如何做到这一点?
Mus*_*usk 21
我必须这样做以防止发送电子邮件.希望能帮助到你.
/*
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;
}
Run Code Online (Sandbox Code Playgroud)
此代码假定您运行上述代码的最新版本的CF7,直到几个月前他们去了并对代码进行了一些重构.
我想补充一点,你可以使用wpcf7_skip_mail过滤器:
add_filter( 'wpcf7_skip_mail', 'maybe_skip_mail' );
function maybe_skip_mail( $skip_mail, $contact_form ) {
if( /* your condition */ )
$skip_mail = true;
return $skip_mail;
}, 10, 2 );
Run Code Online (Sandbox Code Playgroud)
自 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');
Run Code Online (Sandbox Code Playgroud)
或者添加skip_mail到管理区域表单上的“其他设置”选项卡。
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 );
Run Code Online (Sandbox Code Playgroud)
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 );
Run Code Online (Sandbox Code Playgroud)
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 );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38294 次 |
| 最近记录: |