This topic contains 13 replies, has 2 voices, and was last updated by  Anh Tran 11 months, 3 weeks ago.

  • Creator
    Topic
  • #9607

    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

Viewing 10 replies - 1 through 10 (of 13 total)
  • Author
    Replies
  • #9610

    Anh Tran
    Keymaster

    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

    #9765

    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?

    #9801

    Anh Tran
    Keymaster

    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:

    https://github.com/wpmetabox/library/blob/master/extensions/mb-user-profile/register-user-manually.php

    #9816

    Thanks for update, but…

    1. always show error notify “Your username already exists.”

    2. 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

    #9840

    Anh Tran
    Keymaster

    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.

    #9843

    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

    #9882

    Anh Tran
    Keymaster

    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.

    #9886

    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 );
    #9938

    Anh Tran
    Keymaster

    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 );
    #9959

    whit the 2nd snippet the user_email value is not saved in user account

Viewing 10 replies - 1 through 10 (of 13 total)

The topic ‘required fields’ is closed to new replies.