【发布时间】:2020-03-12 08:35:19
【问题描述】:
我正在尝试将“contactform 7”中的信息保存到我的用户个人资料中。
几年前我在这里发现了同样的问题,并尝试了相同的代码,但没有任何成功。
This is the link to the question where I got this code from
下面是我在我的网站上使用的代码
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 title') {
}
global $wpdb;
$user_id = get_current_user_id();
update_user_meta( $user_id, 'email', $posted_data['Email'] );
update_user_meta( $user_id, 'user_login', $posted_data['Gebruikersnaam'] );
update_user_meta( $user_id, 'first_name', $posted_data['billing-first-name'] );
update_user_meta( $user_id, 'last_name', $posted_data['billing-last-name'] );
update_user_meta( $user_id, 'billing_first_name', $posted_data['billing-first-name'] );
update_user_meta( $user_id, 'billing_last_name', $posted_data['billing-last-name'] );
update_user_meta( $user_id, 'billing_company', $posted_data['billing-company'] );
update_user_meta( $user_id, 'billing_address_1', $posted_data['billing-address-1'] );
update_user_meta( $user_id, 'billing_city', $posted_data['billing-city'] );
update_user_meta( $user_id, 'billing_postcode', $posted_data['billing-postcode'] );
}
我之前问过这个问题,但它被标记为离题。可能是因为我的代码太长或不清楚我在说什么。希望这样好吗?
【问题讨论】:
-
到目前为止,您做了哪些尝试和调试?您是否验证过该函数是否被调用?您是否在调试器中单步执行过它,或者至少制作调试输出以验证它走了多远,以及这些
update_user_meta调用返回了什么,如果它已经到了这一步? -
您可能希望将标题编辑为“保存”而不是“安全”,以便对其他人有更多帮助。
标签: php wordpress metadata contact-form-7