the code I am created that makes the users register and auto login. My difficulty is in adding xprofile for this user. Could you help me?
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;
}
the code I am created that makes the users register and auto login. My difficulty is in adding xprofile for this user. Could you help me?
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;
}
Share
Improve this question
edited Dec 19, 2019 at 21:17
shanebp
5,0857 gold badges27 silver badges40 bronze badges
asked Dec 19, 2019 at 1:39
FranciscoFrancisco
32 bronze badges
1 Answer
Reset to default 0You seem to be assuming that the xprofile field id is the same as the user meta field id - if they are, it is just a coincidence. If you have not created xprofile fields, you need to do so. And then use the ids for those xprofile fields. Or you can use the name of the xprofile field
http://hookr.io/functions/xprofile_set_field_data/