1

When making a registration and saving information in the database I want to check if the user's email has already been registrated.

function user_id_exists($user){
    global $wpdb;

    $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->users WHERE ID = %d", $user));

    if($count == 1){ return true; }else{ return false; }
}

It should be something like this

1 Answer 1

2

There's the email_exists() function that could help you with checking if an email already exists among users.

It's e.g. used by register_new_user().

More here:

https://developer.wordpress.org/reference/functions/email_exists/

https://developer.wordpress.org/reference/functions/register_new_user/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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