Assign Role

Home Forums Quform WordPress Assign Role

This topic is: resolved
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #30323
    jennis015
    Participant

    Hi Ally
    How can I add a role to the registrar a user with buddypress?

    BuddyPress registration form

    Thanks very much!
    Regard,

    #30351
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #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);
    #30397
    jennis015
    Participant

    Sorry i forget to told you that im using the plugin of BuddyPress to WordPress Full Sync,

    #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;
    
    } 
    #30426
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #30440
    jennis015
    Participant

    Thanks Ally! Regards!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2019 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy