gpt4 book ai didi

mysql - Contact Form 7 到 Wordpress 用户数据库

转载 作者:行者123 更新时间:2023-11-29 02:23:01 27 4
gpt4 key购买 nike

我编写了以下函数,以便在发送联系人表单时将其添加到用户数据库字段中。问题是它发送了最后一封电子邮件,但没有向数据库输入任何内容,所以我一定是在某处出错了,我们将不胜感激。

add_action('wpcf7_before_send_mail', 'my_conversion');
function my_conversion($cf7) {
global $wpdb;
parse_str($_POST['values'], $cf7->posted_data);
$user_id = get_current_user_id();
update_user_meta( $user_id, 'prefix', $cf7->posted_data['prefix'] );
update_user_meta( $user_id, 'first_name', $cf7->posted_data['first-name'] );
update_user_meta( $user_id, 'middle_name', $cf7->posted_data['middle-name'] );
update_user_meta( $user_id, 'last_name', $cf7->posted_data['last-name'] );
update_user_meta( $user_id, 'suffix', $cf7->posted_data['suffix'] );
update_user_meta( $user_id, 'former_name', $cf7->posted_data['former-name'] );
update_user_meta( $user_id, 'dob', $cf7->posted_data['date-of-birth'] );
update_user_meta( $user_id, 'country_of_birth', $cf7->posted_data['country-of-birth'] );
update_user_meta( $user_id, 'native_language', $cf7->posted_data['native-language'] );
update_user_meta( $user_id, 'city_of_birth', $cf7->posted_data['city-of-birth'] );
update_user_meta( $user_id, 'citizenship', $cf7->posted_data['citizenship'] );
update_user_meta( $user_id, 'citizenship_status', $cf7->posted_data['citizenship-status'] );
update_user_meta( $user_id, 'gender', $cf7->posted_data['gender'] );
update_user_meta( $user_id, 'expiration_date', $cf7->posted_data['expiration-date'] );
update_user_meta( $user_id, 'current_country', $cf7->posted_data['current-country'] );
update_user_meta( $user_id, 'current_city', $cf7->posted_data['current-city'] );
update_user_meta( $user_id, 'primary_address', $cf7->posted_data['primary-address'] );
update_user_meta( $user_id, 'secondary_address', $cf7->posted_data['secondary-address'] );
update_user_meta( $user_id, 'current_state', $cf7->posted_data['current-state'] );
update_user_meta( $user_id, 'zipcode', $cf7->posted_data['zipcode'] );
update_user_meta( $user_id, 'current_resident_country', $cf7->posted_data['current_resident_country'] );
update_user_meta( $user_id, 'current_contact_residence_phone', $cf7->posted_data['current-contact-residence-phone'] );
update_user_meta( $user_id, 'current_contact_business_phone', $cf7->posted_data['current-contact-business-phone'] );
update_user_meta( $user_id, 'current_contact_cell_phone', $cf7->posted_data['current-contact-cell-phone'] );
update_user_meta( $user_id, 'permanent_addr_expiration_date', $cf7->posted_data['permanent-addr-expiration-date'] );
update_user_meta( $user_id, 'permanent_addr_country', $cf7->posted_data['permanent-addr-country'] );
update_user_meta( $user_id, 'permanent_addr_city', $cf7->posted_data['permanent-addr-city'] );
update_user_meta( $user_id, 'permanent_address', $cf7->posted_data['permanent-address'] );
update_user_meta( $user_id, 'permanent_secondary_address', $cf7->posted_data['permanent-secondary-address'] );
update_user_meta( $user_id, 'permanent_current_state', $cf7->posted_data['permanent-current-state'] );
update_user_meta( $user_id, 'permanent_zipcode', $cf7->posted_data['permanent-zipcode'] );
update_user_meta( $user_id, 'permanent_addr_res_county', $cf7->posted_data['permanent_addr_res_county'] );
update_user_meta( $user_id, 'permanent_contact_residence_phone', $cf7->posted_data['permanent-contact-residence-phone'] );
update_user_meta( $user_id, 'permanent_contact_business_phone', $cf7->posted_data['permanent-contact-business-phone'] );
update_user_meta( $user_id, 'permanent_contact_cell_phone', $cf7->posted_data['permanent-contact-cell-phone'] );
update_user_meta( $user_id, 'highest_degree', $cf7->posted_data['highest-degree'] );

update_user_meta( $user_id, 'school_name_num_1', $cf7->posted_data['school-name-num-1'] );
update_user_meta( $user_id, 'school_location_num_1', $cf7->posted_data['school-location-num-1'] );
update_user_meta( $user_id, 'school_attended_from_num_1', $cf7->posted_data['school-attended-from-num-1'] );
update_user_meta( $user_id, 'school_attended_to_num_1', $cf7->posted_data['school-attended-to-num-1'] );
update_user_meta( $user_id, 'school_attended_as_num_1', $cf7->posted_data['school-attended-as-num-1'] );
update_user_meta( $user_id, 'school_major_num_1', $cf7->posted_data['school-major-num-1'] );
update_user_meta( $user_id, 'school_degree_num_1', $cf7->posted_data['school-degree-num-1'] );
update_user_meta( $user_id, 'school_recieved_degree_when_num_1', $cf7->posted_data['school-recieved-degree-when-num-1'] );
update_user_meta( $user_id, 'school_gpa_num_1', $cf7->posted_data['school-gpa-num-1'] );
update_user_meta( $user_id, 'school_transcript_num_1', $cf7->posted_data['school-transcript-num-1'] );

update_user_meta( $user_id, 'school_name_num_2', $cf7->posted_data['school-name-num-2'] );
update_user_meta( $user_id, 'school_location_num_2', $cf7->posted_data['school-location-num-2'] );
update_user_meta( $user_id, 'school_attended_from_num_2', $cf7->posted_data['school-attended-from-num-2'] );
update_user_meta( $user_id, 'school_attended_to_num_2', $cf7->posted_data['school-attended-to-num-2'] );
update_user_meta( $user_id, 'school_attended_as_num_2', $cf7->posted_data['school-attended-as-num-2'] );
update_user_meta( $user_id, 'school_major_num_2', $cf7->posted_data['school-major-num-2'] );
update_user_meta( $user_id, 'school_degree_num_2', $cf7->posted_data['school-degree-num-2'] );
update_user_meta( $user_id, 'school_recieved_degree_when_num_2', $cf7->posted_data['school-recieved-degree-when-num-2'] );
update_user_meta( $user_id, 'school_gpa_num_2', $cf7->posted_data['school-gpa-num-2'] );
update_user_meta( $user_id, 'school_transcript_num_2', $cf7->posted_data['school-transcript-num-2'] );

update_user_meta( $user_id, 'school_name_num_3', $cf7->posted_data['school-name-num-3'] );
update_user_meta( $user_id, 'school_location_num_3', $cf7->posted_data['school-location-num-3'] );
update_user_meta( $user_id, 'school_attended_from_num_3', $cf7->posted_data['school-attended-from-num-3'] );
update_user_meta( $user_id, 'school_attended_to_num_3', $cf7->posted_data['school-attended-to-num-3'] );
update_user_meta( $user_id, 'school_attended_as_num_3', $cf7->posted_data['school-attended-as-num-3'] );
update_user_meta( $user_id, 'school_major_num_3', $cf7->posted_data['school-major-num-3'] );
update_user_meta( $user_id, 'school_degree_num_3', $cf7->posted_data['school-degree-num-3'] );
update_user_meta( $user_id, 'school_recieved_degree_when_num_3', $cf7->posted_data['school-recieved-degree-when-num-3'] );
update_user_meta( $user_id, 'school_gpa_num_3', $cf7->posted_data['school-gpa-num-3'] );
update_user_meta( $user_id, 'school_transcript_num_3', $cf7->posted_data['school-transcript-num-3'] );

update_user_meta( $user_id, 'school_name_num_4', $cf7->posted_data['school-name-num-4'] );
update_user_meta( $user_id, 'school_location_num_4', $cf7->posted_data['school-location-num-4'] );
update_user_meta( $user_id, 'school_attended_from_num_4', $cf7->posted_data['school-attended-from-num-4'] );
update_user_meta( $user_id, 'school_attended_to_num_4', $cf7->posted_data['school-attended-to-num-4'] );
update_user_meta( $user_id, 'school_attended_as_num_4', $cf7->posted_data['school-attended-as-num-4'] );
update_user_meta( $user_id, 'school_major_num_4', $cf7->posted_data['school-major-num-4'] );
update_user_meta( $user_id, 'school_degree_num_4', $cf7->posted_data['school-degree-num-4'] );
update_user_meta( $user_id, 'school_recieved_degree_when_num_4', $cf7->posted_data['school-recieved-degree-when-num-4'] );
update_user_meta( $user_id, 'school_gpa_num_4', $cf7->posted_data['school-gpa-num-3'] );
update_user_meta( $user_id, 'school_transcript_num_4', $cf7->posted_data['school-transcript-num-4'] );

update_user_meta( $user_id, 'school_name_num_5', $cf7->posted_data['school-name-num-5'] );
update_user_meta( $user_id, 'school_location_num_5', $cf7->posted_data['school-location-num-5'] );
update_user_meta( $user_id, 'school_attended_from_num_5', $cf7->posted_data['school-attended-from-num-5'] );
update_user_meta( $user_id, 'school_attended_to_num_5', $cf7->posted_data['school-attended-to-num-5'] );
update_user_meta( $user_id, 'school_attended_as_num_5', $cf7->posted_data['school-attended-as-num-5'] );
update_user_meta( $user_id, 'school_major_num_5', $cf7->posted_data['school-major-num-5'] );
update_user_meta( $user_id, 'school_degree_num_5', $cf7->posted_data['school-degree-num-5'] );
update_user_meta( $user_id, 'school_recieved_degree_when_num_5', $cf7->posted_data['school-recieved-degree-when-num-5'] );
update_user_meta( $user_id, 'school_gpa_num_5', $cf7->posted_data['school-gpa-num-5'] );
update_user_meta( $user_id, 'school_transcript_num_5', $cf7->posted_data['school-transcript-num-5'] );

update_user_meta( $user_id, 'school_name_num_6', $cf7->posted_data['school-name-num-6'] );
update_user_meta( $user_id, 'school_location_num_6', $cf7->posted_data['school-location-num-6'] );
update_user_meta( $user_id, 'school_attended_from_num_6', $cf7->posted_data['school-attended-from-num-6'] );
update_user_meta( $user_id, 'school_attended_to_num_6', $cf7->posted_data['school-attended-to-num-6'] );
update_user_meta( $user_id, 'school_attended_as_num_6', $cf7->posted_data['school-attended-as-num-6'] );
update_user_meta( $user_id, 'school_major_num_6', $cf7->posted_data['school-major-num-6'] );
update_user_meta( $user_id, 'school_degree_num_6', $cf7->posted_data['school-degree-num-6'] );
update_user_meta( $user_id, 'school_recieved_degree_when_num_6', $cf7->posted_data['school-recieved-degree-when-num-6'] );
update_user_meta( $user_id, 'school_gpa_num_6', $cf7->posted_data['school-gpa-num-6'] );
update_user_meta( $user_id, 'school_transcript_num_6', $cf7->posted_data['school-transcript-num-6'] );

update_user_meta( $user_id, 'school_name_num_7', $cf7->posted_data['school-name-num-7'] );
update_user_meta( $user_id, 'school_location_num_7', $cf7->posted_data['school-location-num-7'] );
update_user_meta( $user_id, 'school_attended_from_num_7', $cf7->posted_data['school-attended-from-num-7'] );
update_user_meta( $user_id, 'school_attended_to_num_7', $cf7->posted_data['school-attended-to-num-7'] );
update_user_meta( $user_id, 'school_attended_as_num_7', $cf7->posted_data['school-attended-as-num-7'] );
update_user_meta( $user_id, 'school_major_num_7', $cf7->posted_data['school-major-num-7'] );
update_user_meta( $user_id, 'school_degree_num_7', $cf7->posted_data['school-degree-num-7'] );
update_user_meta( $user_id, 'school_recieved_degree_when_num_7', $cf7->posted_data['school-recieved-degree-when-num-7'] );
update_user_meta( $user_id, 'school_gpa_num_7', $cf7->posted_data['school-gpa-num-7'] );
update_user_meta( $user_id, 'school_transcript_num_7', $cf7->posted_data['school-transcript-num-7'] );

update_user_meta( $user_id, 'school_name_num_8', $cf7->posted_data['school-name-num-8'] );
update_user_meta( $user_id, 'school_location_num_8', $cf7->posted_data['school-location-num-8'] );
update_user_meta( $user_id, 'school_attended_from_num_8', $cf7->posted_data['school-attended-from-num-8'] );
update_user_meta( $user_id, 'school_attended_to_num_8', $cf7->posted_data['school-attended-to-num-8'] );
update_user_meta( $user_id, 'school_attended_as_num_8', $cf7->posted_data['school-attended-as-num-8'] );
update_user_meta( $user_id, 'school_major_num_8', $cf7->posted_data['school-major-num-8'] );
update_user_meta( $user_id, 'school_degree_num_8', $cf7->posted_data['school-degree-num-8'] );
update_user_meta( $user_id, 'school_recieved_degree_when_num_8', $cf7->posted_data['school-recieved-degree-when-num-8'] );
update_user_meta( $user_id, 'school_gpa_num_8', $cf7->posted_data['school-gpa-num-8'] );
update_user_meta( $user_id, 'school_transcript_num_8', $cf7->posted_data['school-transcript-num-8'] );

update_user_meta( $user_id, 'carreer_field', $cf7->posted_data['carreer-field'] );
update_user_meta( $user_id, 'carreer_field_spec', $cf7->posted_data['carreer-field-spec'] );

update_user_meta( $user_id, 'exper_1_position_title', $cf7->posted_data['exper-1-position-title'] );
update_user_meta( $user_id, 'exper_1_organization_name', $cf7->posted_data['exper-1-organization-name'] );
update_user_meta( $user_id, 'exper_1_country', $cf7->posted_data['exper-1-country'] );
update_user_meta( $user_id, 'exper_1_city', $cf7->posted_data['exper-1-city'] );
update_user_meta( $user_id, 'exper_1_from', $cf7->posted_data['exper-1-from'] );
update_user_meta( $user_id, 'exper_1_to', $cf7->posted_data['exper-1-to'] );

update_user_meta( $user_id, 'exper_2_position_title', $cf7->posted_data['exper-2-position-title'] );
update_user_meta( $user_id, 'exper_2_organization_name', $cf7->posted_data['exper-2-organization-name'] );
update_user_meta( $user_id, 'exper_2_country', $cf7->posted_data['exper-2-country'] );
update_user_meta( $user_id, 'exper_2_city', $cf7->posted_data['exper-2-city'] );
update_user_meta( $user_id, 'exper_2_from', $cf7->posted_data['exper-2-from'] );
update_user_meta( $user_id, 'exper_2_to', $cf7->posted_data['exper-2-to'] );

update_user_meta( $user_id, 'exper_3_position_title', $cf7->posted_data['exper-3-position-title'] );
update_user_meta( $user_id, 'exper_3_organization_name', $cf7->posted_data['exper-3-organization-name'] );
update_user_meta( $user_id, 'exper_3_country', $cf7->posted_data['exper-3-country'] );
update_user_meta( $user_id, 'exper_3_city', $cf7->posted_data['exper-3-city'] );
update_user_meta( $user_id, 'exper_3_from', $cf7->posted_data['exper-3-from'] );
update_user_meta( $user_id, 'exper_3_to', $cf7->posted_data['exper-3-to'] );

update_user_meta( $user_id, 'exper_4_position_title', $cf7->posted_data['exper-4-position-title'] );
update_user_meta( $user_id, 'exper_4_organization_name', $cf7->posted_data['exper-4-organization-name'] );
update_user_meta( $user_id, 'exper_4_country', $cf7->posted_data['exper-4-country'] );
update_user_meta( $user_id, 'exper_4_city', $cf7->posted_data['exper-4-city'] );
update_user_meta( $user_id, 'exper_4_from', $cf7->posted_data['exper-4-from'] );
update_user_meta( $user_id, 'exper_4_to', $cf7->posted_data['exper-4-to'] );

update_user_meta( $user_id, 'exper_5_position_title', $cf7->posted_data['exper-5-position-title'] );
update_user_meta( $user_id, 'exper_5_organization_name', $cf7->posted_data['exper-5-organization-name'] );
update_user_meta( $user_id, 'exper_5_country', $cf7->posted_data['exper-5-country'] );
update_user_meta( $user_id, 'exper_5_city', $cf7->posted_data['exper-5-city'] );
update_user_meta( $user_id, 'exper_5_from', $cf7->posted_data['exper-5-from'] );
update_user_meta( $user_id, 'exper_5_to', $cf7->posted_data['exper-5-to'] );

update_user_meta( $user_id, 'exper_6_position_title', $cf7->posted_data['exper-6-position-title'] );
update_user_meta( $user_id, 'exper_6_organization_name', $cf7->posted_data['exper-6-organization-name'] );
update_user_meta( $user_id, 'exper_6_country', $cf7->posted_data['exper-6-country'] );
update_user_meta( $user_id, 'exper_6_city', $cf7->posted_data['exper-6-city'] );
update_user_meta( $user_id, 'exper_6_from', $cf7->posted_data['exper-6-from'] );
update_user_meta( $user_id, 'exper_6_to', $cf7->posted_data['exper-6-to'] );

update_user_meta( $user_id, 'exper_7_position_title', $cf7->posted_data['exper-7-position-title'] );
update_user_meta( $user_id, 'exper_7_organization_name', $cf7->posted_data['exper-7-organization-name'] );
update_user_meta( $user_id, 'exper_7_country', $cf7->posted_data['exper-7-country'] );
update_user_meta( $user_id, 'exper_7_city', $cf7->posted_data['exper-7-city'] );
update_user_meta( $user_id, 'exper_7_from', $cf7->posted_data['exper-7-from'] );
update_user_meta( $user_id, 'exper_7_to', $cf7->posted_data['exper-7-to'] );

update_user_meta( $user_id, 'exper_8_position_title', $cf7->posted_data['exper-8-position-title'] );
update_user_meta( $user_id, 'exper_8_organization_name', $cf7->posted_data['exper-8-organization-name'] );
update_user_meta( $user_id, 'exper_8_country', $cf7->posted_data['exper-8-country'] );
update_user_meta( $user_id, 'exper_8_city', $cf7->posted_data['exper-8-city'] );
update_user_meta( $user_id, 'exper_8_from', $cf7->posted_data['exper-8-from'] );
update_user_meta( $user_id, 'exper_8_to', $cf7->posted_data['exper-8-to'] );

update_user_meta( $user_id, 'conv_area1', $cf7->posted_data['conv-area1'] );
update_user_meta( $user_id, 'conv_area2', $cf7->posted_data['conv-area2'] );
update_user_meta( $user_id, 'research_area1', $cf7->posted_data['research-area1'] );
update_user_meta( $user_id, 'research_area2', $cf7->posted_data['research-area2'] );
update_user_meta( $user_id, 'research_area3', $cf7->posted_data['research-area3'] );
update_user_meta( $user_id, 'research_area4', $cf7->posted_data['research-area4'] );
update_user_meta( $user_id, 'application_status', 'I' );

global $current_user;
get_currentuserinfo();
$email_address = 'email@address.com';
// write the email content
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html; charset=utf-8\n";
$header .= "From:" . $email_address;
$subject = 'W Application Form';
$message = "Hi,<br/><br/>".$cf7->posted_data['first-name'].' '.$cf7->posted_data['last-name']."<br/><br/>";
$message .= "Your application has been submitted successfully";
wp_mail($current_user->user_email, $subject, $message, $header);
//$current_user->user_email
}

我还尝试了另一种方法来做到这一点,下面是基于其他示例和 WP codex 的方法,但这也不起作用吗?

   add_action('wpcf7_before_send_mail', 'updateuser');
function updateuser($cf7)
{
$first_name = $cf7->posted_data["first-name"];
$middle_name = $cf7->posted_data["middle-name"];
$last_name = $cf7->posted_data["last-name"];

global $wpdb, $wpcf7;
global $current_user;
get_currentuserinfo();
$wpdb->update(
'usermeta',
array (
'first_name' => $first_name,
'middle_name' => $middle_name,
'last_name' => $last_name
),
array( 'ID' => $userid ),
array(
'%s',
'%s',
'%s'
),
array( '%d' )
);

global $current_user;
get_currentuserinfo();
$email_address = 'contact@domain.com';
// write the email content
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html; charset=utf-8\n";
$header .= "From:" . $email_address;
$subject = 'New Application Form';
$message = "Hi,<br/><br/>".$cf7->posted_data['first-name'].' '.$cf7->posted_data['last-name']."<br/><br/>";
$message .= "Your application has been submitted successfully";
wp_mail($current_user->user_email, $subject, $message, $header);
//$current_user->user_email
}
?>

最佳答案

经过多次试验和谷歌搜索并遵循 Howli 的建议,我终于到达了那里,这段代码可以更新 usermeta 表,希望它可以帮助人们节省数小时的时间:

add_action('wpcf7_before_send_mail', 'cf7import',1);
function cf7import() {
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
if ( $submission )
{
$posted_data = $submission->get_posted_data();
$formtitle = $cfdata->title; }
if ( $formtitle == 'Form Name') {
}
global $wpdb;
$user_id = get_current_user_id();
update_user_meta( $user_id, 'prefix', $posted_data['prefix'] );
update_user_meta( $user_id, 'first_name', $posted_data['first-name'] );
update_user_meta( $user_id, 'middle_name', $posted_data['middle-name'] );
update_user_meta( $user_id, 'last_name', $posted_data['last-name'] );

关于mysql - Contact Form 7 到 Wordpress 用户数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28137624/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com