Support Forum
Support › MB User Profile › required fields
Hi,
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 form
Hello,
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
Hi 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?
Hello,
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:
Thanks 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
Hi, 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.
Hi 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
Can 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.
Hi Anh,
now it's works.
Another question:
if I would to customize only username e password, but insert user_email field in form, I use
add_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 );
Ah, 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 );
whit the 2nd snippet the user_email value is not saved in user account
I'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
I solved by using user_register action
add_action( 'user_register', 'test');
function test( $user_id ) {
add_user_meta( $user_id, 'user_field', 'field_value' );
}
Yes, 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.