Add User in wordpress without username

I have made a registration form which have only two fields email and password .Now i want to add user to WordPress database but wp_create_user() require username too.Then i tried using another function as $status=wp_insert_user($userdata); where $userdata is an array containing elements as

$userdata = array(
                'user_pass'   =>  $pswrd,
                'user_email'=> $email
            );

but user is not added in database. Is their any other function through which i can add user with above two fields only.

Related posts

2 comments

  1. If you don’t want to ask the user for a specific login name, you could use their e-mail:

    if ( !username_exists( $email ) {
        $user_id = wp_create_user( $email, $pswrd, $email );
    
        if ( !is_wp_error( $user_id ) ) {
            // created succesfully
    
        }
    } else {
        // Username already exists
    
    }
    

Comments are closed.