add_action('wpcf7_before_send_mail','bin_opt_in_contact');function bin_opt_in_contact($cf7)
函数bin_opt_in_contact($ cf7)
{
{
// Get current form id
//获取当前表单ID
$formId = $cf7->id;
$ formId = $ cf7-> id;
// Array of form ids
//表单ID的数组
$forms = [159, 454];
$ forms = [159,454];
// Only apply to certain forms
//仅适用于某些表格
if(in_array($formId, $forms))
if(in_array($ formId,$ forms))
{
{
// Dont do anything if class is missing
//如果缺少课程,请不要做任何事情
if(class_exists('BinOptIn'))
如果(class_exists('BinOptIn'))
{
{
// At least, the email must be present
//至少必须存在该电子邮件
if(is_email($_POST['email']))
if(is_email($ _ POST ['email']))
{
{
// map salutation
//地图称呼
$salutationMap = [
$ salutationMap = [
'Frau' => 0,
'Frau'=> 0,
'Madame' => 0,
'女士'=> 0,
'Mrs' => 0,
'太太'=> 0,
'Herr' => 1,
'Herr'=> 1,
'Monsieur' => 1,
'先生'=> 1,
'Mr' => 1,
'先生'=> 1,
'*' => 2
'*'=> 2
];
];
// assign form data with corresponding meta fields
//为表单数据分配相应的元字段
$postdata = [];
$ postdata = [];
$postdata['email'] = sanitize_email($_POST['email']);
$ postdata ['email'] = sanitize_email($ _ POST ['email']);
$postdata['first_name'] = sanitize_text_field($_POST['first_name']);
$ postdata ['first_name'] = sanitize_text_field($ _ POST ['first_name']);
$postdata['last_name'] = sanitize_text_field($_POST['last_name']);
$ postdata ['last_name'] = sanitize_text_field($ _ POST ['last_name']);
$postdata['salutation'] = $salutationMap[$_POST['salutation']];
$ postdata ['salutation'] = $ salutationMap [$ _ POST ['salutation']];
$postdata['terms_and_conditions_accepted'] = isset($_POST['terms_and_conditions_accepted']) ?
$ postdata ['terms_and_conditions_accepted'] = isset($ _ POST ['terms_and_conditions_accepted'])吗?
'yes' : '';
'是':'';
// save contact
//保存联系人
BinOptIn::optIn($postdata, [
BinOptIn :: optIn($ postdata,[
'opt_in_admin_message' => false,
'opt_in_admin_message'=>否,
'double_opt_in' => false,
'double_opt_in'=>否,
'admin_unlock' => false,
'admin_unlock'=>否,
'unlock_message' => false
'unlock_message'=>否
]);
]);
}
}
}
}
}
}
}