Reply To: Assign Role

Home Forums Quform WordPress Assign Role Reply To: Assign Role

#30396
jennis015
Participant

HI Ally
I have working a long time with this:
I cant use easily bp_core_activated_user because i have desactived the activaction for autologin after complete the form ..

so these code begin works: it create a new user like *shop_manager* (this rol isnt for default)

the problem is add the fields of xprofile to the user, this way dont work, do you have a better idea?

Thanks very much!

add_filter('quform_element_valid_7_6', function ($valid, $value, Quform_Element_Field $element) {
    if (username_exists($value)) {
        $element->addError('El nombre de usuario no esta disponible');
        $valid = false;
    }
 
    return $valid;
}, 10, 3);
 
add_filter('quform_element_valid_7_6', function ($valid, $value, Quform_Element_Field $element) {
    if (email_exists($value)) {
        $element->addError('El correo ya ha sido registrado');
        $valid = false;
    }
 
    return $valid;
}, 10, 3);
 
add_action('quform_post_process_7', function (array $result, Quform_Form $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,
    ));
     update_user_meta( $user_id, '_is_shop_manager', 1 );
 
    return $result;
}, 10, 2);

function something_updated_profile() {
 global $current_user;
    get_currentuserinfo();
    
$user = get_userdata( $user_id );
	$is_shopmanager = get_user_meta( $user_id, '_is_shop_manager', true );
	if ( $is_shopmanager ) {
	// XProfile fields
	
	
	$usermeta = array(

'field_1' => $form->getValueText('quform_7_28'),
'field_43' => $form->getValueText( 'quform_7_6' ),
'field_44' => $form->getValueText('quform_7_20'),
'field_62' => $form->getValueText('quform_7_14'),
'field_64'  => $form->getValueText('quform_7_11'),
'field_59' => 'Inmobiliaria',
'field_99' => $form->getValueText('quform_7_23'),
'field_103' => $form->getValueText('quform_7_41'),
'field_104' => $form->getValueText('quform_7_42'),
 'field_105' => $form->getValueText('quform_7_40'), 
 'field_106' => $form->getValueText('quform_7_46'),
'field_107'=> $form->getValueText('quform_7_43'),
'field_108' => $form->getValueText('quform_7_44'),
'field_109' => $form->getValueText('quform_7_45'),
 'field_110' => $form->getValueText('quform_7_47'),
 'field_111' => $form->getValueText('quform_7_48'),
	);
       $usermeta['profile_field_ids'] = '1,43,44,46,48,47,49,50,51,59';
        $usermeta['password'] = wp_hash_password($password);
}}
add_action('xprofile_updated_profile', 'something_updated_profile', 1, 3);
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy