Reply To: Assign Role

Home Forums Quform WordPress Assign Role Reply To: Assign Role

#30398
jennis015
Participant

Hi Ally

I’m closer .. it works to create the user with his role. My difficulty is to add 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;

} 
Be inspired. © 2019 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy