How to Allow Users to Set Password During Registration

After learning how to register additional contact information fields and display them in WordPress register form, it’s time to take a look at how to allow users to set their own passwords when they register. You can achieve that using the same logic from previous post, with slightly different custom functions that you’ll hook into some WordPress filter and action hooks.

Once again, we begin by showing a few extra fields in WordPress registration form and checking user’s input. This time, it’s password and repeat password field, but in order to fight spam account we’ll add one of those beloved “Are you human?” fields as well. Here’s the code:

Our ts_check_extra_register_fields function performs three checks:

  1. First it makes sure passwords match
  2. Then it checks if password is at least eight characters long
  3. Finally, it compares value from “are you human” field to WordPress site title

If any of these conditions are not met, error message will be displayed above the register form. If all is well, WordPress will move on to creating a new user account. But, since we want WordPress to store password into database, rather than generate its own, we need to hook our ts_register_extra_fields function into user_register action hook:

It’s dead simple, if password field was left empty our function does nothing. If the field has a certain value, it passes it to $userdata array as $userdata['user_pass'].

That would be all if it wasn’t for that annoying “A password will be e-mailed to you.” message near the end of WordPress registration form. Luckily, it can be easily replaced by hooking into gettext filter hook:

Why would you want to do this? Well, while most users won’t mind having a password set for them, it still might be better to treat them like humans and let them set their own. Of course, you can copy all the code to functions.php file inside your theme folder or turn it into a plugin by simply merging it into one PHP file and adding standard plugin information (plugin header) to it.

15 thoughts on “How to Allow Users to Set Password During Registration

  1. Nice!! But when registering, it still sending the mail with the auto-generated password and ain’t no works because the correct password is the one inserted in the registration page.
    How can I disable this?
    Thanks again for this good function!

  2. is there a way of getting rid of are you human question ? I tried to delete it but it’s still there :) Thanks. Otherwise it’s great. Keep it going :)

  3. I actually have a problem. I saw that only now when I signed out all my links have are broken because I removed the input and label for the question.when I put it back no problem whatsoever. ever had this problem?

  4. sorry for my typos I’m tired of looking through code I’ve asked stupid questions all day long. Anyway I registered using the form no problem.. without the question but for some reason it stopped working after 4-5 hours without doing anything to it.. so.. don’t know what to say..

  5. Thanks for this article.
    The only problem is that when WordPress emails a confirmation to the user, it still uses the password it generates and not the password the user set…
    How do I fix that?

    Thanks
    Cameron

  6. The email with a password still gets sent to the new registered user. Also , after registering, the notification appears: Registration complete. Please check your e-mail. Is there a way to stop the email and remove that notification or auto login the user after registration?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>