0

I am using the

<?php wp_create_user( $username, $password, $email ); ?>

function in a contact form to create a subscriber when the user enters infomation on the contact form, thus in the background adding their email address to the database and giving them an account for site access.

Does this way of doing it though not mean that if a user sends 3 messages from the contact form they end up with 3 accounts with the same email address, or will it check to see if the email address or user name already exists.

Any ideas?

1

The function wp_create_user calls ‪wp_insert_user‬ which check to see if $username and $email already exists and if so it returns a new WP_Error so you wont have duplicate users in your database and it wont send the new user email more then once, but i'm not sure if that is the best way to do that.

| improve this answer | |
0

You can avoid duplicate users by using username_exists function.

$username = $_POST['username'];
if ( username_exists( $username ) )
    echo "Username In Use!";
else
    echo "Username Not In Use!";
| improve this answer | |

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.