required fields
Support › MB User Profile › required fields
- This topic has 13 replies, 2 voices, and was last updated 6 years, 11 months ago by
Anh Tran.
-
AuthorPosts
-
May 21, 2018 at 4:09 PM #9607
ingegnimultimediali
ParticipantHi,
this new extension include as required fields in frontend registration form: username, email and double password fields.
Is there the possibility to exclude these fields and leave only the meta-box fields in the frontend form?
e.g. I would to create new user by frontend form, but username and password are generated by a hook after submit formMay 21, 2018 at 10:25 PM #9610Anh Tran
KeymasterHello,
It would be hard as the custom fields created by Meta Box needs to hook in to the
wp_insert_user
to save the data. If you manually create the user, that code should happen before the form is processed. Let me see if I can provide a way to do that. Please wait.Anh
May 27, 2018 at 12:37 PM #9765ingegnimultimediali
ParticipantHi Anh,
any updates?
I'm thinking about a solution with rwmb_profile_insert_user_data
If I hidden required fields in the form, is it possible to set custom value by user data filter?
what do you think about it?May 28, 2018 at 2:59 PM #9801Anh Tran
KeymasterHello,
I've just updated the plugin (v1.0.1) that add support for ignoring the register process and allow you to register the user by your own. Please update and see the demo code here:
May 28, 2018 at 10:32 PM #9816ingegnimultimediali
ParticipantThanks for update, but...
-
always show error notify "Your username already exists."
-
after submit form --> Fatal error: Uncaught Error: Call to undefined function info() in /home/xxxxxxxx/wp-content/plugins/mb-user-profile/inc/class-mb-user-profile-user.php:105 Stack trace: #0 /home/xxxxxxxx/wp-content/plugins/mb-user-profile/inc/class-mb-user-profile-user.php(57): MB_User_Profile_User->create() #1 /home/xxxxxxxx/wp-content/plugins/mb-user-profile/inc/forms/class-mb-user-profile-form.php(110): MB_User_Profile_User->save() #2 /home/xxxxxxxx/wp-content/plugins/mb-user-profile/inc/shortcodes/class-mb-user-profile-shortcode-register.php(43): MB_User_Profile_Form->process() #3 /home/xxxxxxxx/wp-includes/class-wp-hook.php(286): MB_User_Profile_Shortcode_Register->process('') #4 /home/xxxxxxxx/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #5 /home/xxxxxxxx/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #6 /home/xxxxxxxx/wp-includes/template-loader.php(12): do in /home/xxxxxxxx/wp-content/plugins/mb-user-profile/inc/class-mb-user-profile-user.php on line 105
May 29, 2018 at 12:19 PM #9840Anh Tran
KeymasterHi, I've just updated the plugin to remove the debug function in the #2 error :(. Sorry about that.
Regarding the #1: you need to change the code at this line to your code that register users. If you submit multiple times, it returns the same user info and thus, WordPress will throw an error of existing username/email.
May 29, 2018 at 2:08 PM #9843ingegnimultimediali
ParticipantHi anh,
the update action to 1.0.2 fail...and the #2 error remaining...
Fatal error: Uncaught Error: Call to undefined function info() in /home/xxxxxxxx/wp-content/plugins/mb-user-profile/inc/class-mb-user-profile-user.php:105 Stack trace: #0 /home/xxxxxxxx/wp-content/plugins/mb-user-profile/inc/class-mb-user-profile-user.php(57): MB_User_Profile_User->create() #1 /home/xxxxxxxx/wp-content/plugins/mb-user-profile/inc/forms/class-mb-user-profile-form.php(110): MB_User_Profile_User->save() #2 /home/xxxxxxxx/wp-content/plugins/mb-user-profile/inc/shortcodes/class-mb-user-profile-shortcode-register.php(43): MB_User_Profile_Form->process() #3 /home/xxxxxxxx/wp-includes/class-wp-hook.php(286): MB_User_Profile_Shortcode_Register->process('') #4 /home/xxxxxxxx/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #5 /home/xxxxxxxx/website/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #6 /home/xxxxxxxx/wp-includes/template-loader.php(12): do in /home/xxxxxxxx/wp-content/plugins/mb-user-profile/inc/class-mb-user-profile-user.php on line 105
May 30, 2018 at 10:05 AM #9882Anh Tran
KeymasterCan you please try updating again? I've just checked and there's no problem.
If the update fails, can you send me the error message? The #2 error will be still there if you couldn't update.
May 30, 2018 at 11:06 AM #9886ingegnimultimediali
ParticipantHi Anh,
now it's works.Another question:
if I would to customize only username e password, but insert user_email field in form, I useadd_filter( 'rwmb_profile_register_fields', 'addfield', 10, 1); function addfield($fields){ $fields = array( array( 'type' => 'email', 'name' => 'Email', 'id' => 'user_email', 'required' => 1 )); return $fields; }
to display user_email with my form
This hook works but not save user_email value in user account
I've used this rwmb_profile_insert_user_data
add_filter( 'rwmb_profile_insert_user_data', function ( $data, $config ) { // User strpos because the $config also contains default register form. if ( false === strpos( $config['id'], 'user-account' ) ) { return $data; } // Custom data for user. $data = [ 'user_login' => 'my_user3', 'user_pass' => 'my_user_pass', ]; return $data; }, 10, 2 );
May 31, 2018 at 5:17 PM #9938Anh Tran
KeymasterAh, if you want to keep the
email
field, then in the 2nd snippet, it's available in the$data
, so you should keep it (e.g. don't assign it to a completely new array).The 2nd snippet should be:
add_filter( 'rwmb_profile_insert_user_data', function ( $data, $config ) { // User strpos because the $config also contains default register form. if ( false === strpos( $config['id'], 'user-account' ) ) { return $data; } // Custom data for user. $data['user_login'] = 'my_user3'; $data['user_pass'] = 'my_user_pass'; return $data; }, 10, 2 );
June 1, 2018 at 9:55 AM #9959ingegnimultimediali
Participantwhit the 2nd snippet the user_email value is not saved in user account
June 1, 2018 at 10:25 AM #9961ingegnimultimediali
ParticipantI'm sorry for last reply... the 2nd snippet is correct and it works fine
using rwmb_profile_insert_user_data is it possible to return the
$this->user_id = wp_insert_user( $data );??
Know the user_id value will allow to do many other things
June 1, 2018 at 10:33 AM #9962ingegnimultimediali
ParticipantI solved by using user_register action
add_action( 'user_register', 'test');
function test( $user_id ) {
add_user_meta( $user_id, 'user_field', 'field_value' );
}
June 1, 2018 at 12:07 PM #9966Anh Tran
KeymasterYes, your last snippet will work.
I just wander why do you need to update a custom user meta? Doesn't it belong to a Meta Box? If it does, the Meta Box can handle all the saving. In case you want to add custom meta, beyond the scope of Meta Box, yes, it makes sense.
-
-
AuthorPosts
- The topic ‘required fields’ is closed to new replies.