• Resolved kalleaume

    (@kalleaume)


    When using a registration form without the username field, I note that a username is generated from the first part of the user’s email (everything before the @ symbol). For example, [email protected] has a username of ‘johnsmith’. This works fine… until a second user registers with an email address with the same text before the @ symbol, for example [email protected]. In this case, the registration form freezes. It does not Submit, and it also does not display any error message to the user. Please advise how we can fix this.

    I looked through your support forum and noticed this post about setting the username to be the user’s first and last name instead. This is not ideal because the same duplicate issue can occur this way. Therefore, we want to set the username as the user’s full email address, as this will ensure there is no possibility for a duplicate, which means the form won’t freeze again. Could you please advise how we can set this up?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Same for me…

    Hello, I need same, I mean for my project login and email should be same, could you please tell if this is a good solution :

    <?php// Force update our username (user_login)global $wpdb;$tablename = $wpdb->prefix . “users”;// method 1//$sql = $wpdb->prepare(“UPDATE %s SET user_login=%s WHERE ID=%d”, $tablename, $user_email, $user_id);//$wpdb->query($sql);// method 2$wpdb->update( $tablename, array( ‘user_login’ => $user_email ), array( ‘ID’ => $user_id ) );?>

    Just find out here :

    https://gist.github.com/mattboon/4045215

    Thanks

    Olga

    Hello, I’m not a coder, just a software small shop, anyway after few hours of internet search with help of a string search program, just find out the position where when in the form is missing the Username it will be replaced with initial part of Email as per question of this support post.

    You have to go to INCLUDES – FRONTEND – class-ur-frontend-form-handler.php LINE 95

    if ( empty( $userdata[‘user_login’] ) ) {

    $part_of_email = explode( ‘@’, $userdata[‘user_email’] );

    $username = check_username( $part_of_email[0] );

    $userdata[‘user_login’] = $username;

    }

    This is where if login is empty it takes the substring of email, I just have make same small change to let it works without doing this but just using the full email

    if ( empty( $userdata[‘user_login’] ) ) {

    //$part_of_email = explode( ‘@’, $userdata[‘user_email’] );

    $part_of_email = $userdata[‘user_email’];

    //$username = check_username( $part_of_email [0] );

    $username = check_username( $part_of_email);

    $userdata[‘user_login’] = $username;

    // $userdata[‘user_login’] = $userdata[‘user_email’]

    }

    It works fine, even if I’m not a coder but this will work until the plugin have an UPDATE otherwise you have to go again in the file and repeat the change if update have some effect on the file.

    I would be very happy if the programmers would implement the possibility (a flag or something else) that if ON would force the EMAIL field as LOGIN as an alternative and in the meantime give us a hint on how to put this code using the SNIPPETS PLUGIN to work regardless of updates. THANKS IN ADVANCE

    I have just arrived at a better solution without modifying the Plugin, in which case the INPUT of the PLUGIN’s UserName user_login must also be present.
    Putting this code at the bottom of the page where the Form is, hides the INPUT of the UserName user_login but populates it with what is typed into the INPUT of the Email user_email.

    <script>
    document.getElementById("user_login_field").style.visibility = "hidden";
    document.getElementById('user_email').onkeyup = function() {document.getElementById('user_login').value = document.getElementById('user_email').value};
    </script>
    
    
    Thread Starter kalleaume

    (@kalleaume)

    Hi WP Everest,

    As the developers of this plugin, could you please advise us on whether you would recommend either of the solutions suggested by @olgaengel80 and @anziosoftware?

    Ideally, I would like to be able to insert code into the code snippets plugin, just as a temporary solution until the plugin can be updated to address this issue.

    • This reply was modified 1 year, 6 months ago by kalleaume.
    Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    Hi everyone,

    Please use the following code snippet to fix the mentioned issue. This code will help you to generate the user name with the full email provided by the user during registration.

    add_action( 'user_registration_after_register_user_action', 'ur_insert_username', 1, 3 );
    function ur_insert_username( $valid_form_data, $form_id, $user_id ) {
    global $wpdb;
    $user_email = isset( $valid_form_data['user_email'] ) ? $valid_form_data['user_email']->value : '';
    if( !empty($user_email)) {
    $wpdb->update(
    $wpdb->users,
    ['user_login' => $user_email],
    ['ID' => $user_id]
    );
    }
    }

    If you do not know where to add the code snippet on your site, please check this documentation https://docs.wpeverest.com/user-registration/docs/custom-code-snippets/ and follow the instruction.

    Regards!

    Thread Starter kalleaume

    (@kalleaume)

    Thanks so much for your response, @shresthauzwal. I tested that code snippet and it is working perfectly now. I really appreciate your prompt response to this issue! Thank you.

    Do you think this will become part of the actual plugin code in the future?

    • This reply was modified 1 year, 6 months ago by kalleaume.

    Thanks for support, great job !

    Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    We will include this fix in our upcoming update, so you do need to worry about it. ?If you have a moment to spare, then we would really appreciate your review of our plugin. Please click this link:?https://www.ads-software.com/support/plugin/user-registration/reviews/#new-post, and share your thoughts about our team and plugin. We would love to hear from you.
    ?
    Thanks in advance ??

    Regards!

    Thread Starter kalleaume

    (@kalleaume)

    @shresthauzwal, following on from your post here, I understand that the code snippet you provided above is not compatible with the current version of the plugin (Version 3.0 onwards) as it causes the Auto login feature to stop working.

    I’m just updating this thread here so that others following this issue are made aware of the Auto login issue. I have also marked this issue as ‘not resolved’, so that we can mark it as resolved once a new solution is provided. I understand from your other post that you will be updating the documentation here once a solution is found. Would you kindly update us in this thread also once that occurs please?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Use full email address as username’ is closed to new replies.