Home › Forums › Quform WordPress › Assign Role
- This topic has 6 replies, 2 voices, and was last updated 5 years, 4 months ago by
jennis015.
- AuthorPosts
- December 3, 2019 at 10:26 am #30323
jennis015
ParticipantHi Ally
How can I add a role to the registrar a user with buddypress?Thanks very much!
Regard,December 6, 2019 at 11:02 am #30351Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
December 17, 2019 at 10:53 pm #30396jennis015
ParticipantHI 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);
December 17, 2019 at 10:56 pm #30397jennis015
ParticipantSorry i forget to told you that im using the plugin of BuddyPress to WordPress Full Sync,
December 19, 2019 at 2:03 am #30398jennis015
ParticipantHi 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; }
January 6, 2020 at 9:29 am #30426Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
January 6, 2020 at 9:13 pm #30440jennis015
ParticipantThanks Ally! Regards!
- AuthorPosts
- You must be logged in to reply to this topic.