我创建的代码可以让用户注册并自动登录。我的困难在于为该用户添加xprofile。你能帮帮我吗?
add_action(\'quform_post_process_7\',\'register\', 10, 2);
function register ($result, $form) {
$username = $form->getValueText( \'quform_7_6\' );
$email = $form->getValueText( \'quform_7_6\' );
$password = $form->getValueText( \'quform_7_7\' );
$role = \'shop_manager\';
$userId = wp_insert_user(array(
\'user_login\' => $username,
\'user_pass\' => $password,
\'user_email\' => $email,
\'role\' => $role,
));
$hash = wp_hash_password($password);
update_user_meta( $user_id, \'_is_shop_manager\', 1 );
update_user_meta($userId, \'nickname\', $form->getValueText(\'quform_7_28\'));
update_user_meta($userId, \'first_name\', $form->getValueText(\'quform_7_28\'));
if(!is_wp_error( $userId)){
wp_set_current_user( $userId); // set the current wp user
wp_set_auth_cookie( $userId); // startthe cookie for the current registered user
if (bp_is_active(\'xprofile\')) {
if (!empty($usermeta[\'1,43,44\'])) {
$profile_field_ids = explode(\',\', $usermeta[\'1,43,44\']);
foreach ((array) $profile_field_ids as $field_id) {
if (empty($usermeta["field_1"])) {
$usermeta = array(
\'field_1\' => $form->getValueText(\'quform_7_28\'),
\'field_43\' => $form->getValueText( \'quform_7_6\' ),
\'field_44\' => $form->getValueText(\'quform_7_20\'),
);
}
$current_field = $usermeta["field_1"];
xprofile_set_field_data($field_id, $user_id, $current_field);
}
}
}
}
return $result;
}