-3

Is it possible to create a form on my front-page which concludes email, name and surname and when its submitted it creates a new wordpress user with a random password?

I need this function to create new wordpress users which are synchronized to mailchimp.

  • 3
    Please, explain in detail what you need, show what you have tried, where and how you failed and where you are stuck (in code). File an edit and take your time to read How to Ask. As it currently stands, the Community bot will remove your answer during scheduled clean up (and due to down votes for quality) and your flag count for "low quality" will rise. You better avoid that :) – kaiser Jul 11 '16 at 14:40
13

it's right here in the codex.

This is example code, showing how a new user is created:

$user_id = username_exists( $user_name );
if ( !$user_id and email_exists($user_email) == false ) {
    $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
    $user_id = wp_create_user( $user_name, $random_password, $user_email );
} else {
    $random_password = __('User already exists.  Password inherited.');
}

and here, another wrapper version with more functionality.

$website = "http://example.com";
$userdata = array(
    'user_login'  =>  'login_name',
    'user_url'    =>  $website,
    'user_pass'   =>  NULL  // When creating an user, `user_pass` is expected.
);

$user_id = wp_insert_user( $userdata ) ;

//On success
if ( ! is_wp_error( $user_id ) ) {
    echo "User created : ". $user_id;
}

The part about constructing the form, integrating with mailchip, etc - better to be asked in a different question if you need to see examples of code to cover that part of your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.