WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/email exists

Description

This function will check whether or not a given email address ($email) has already been registered to a username, and returns that users ID (or false if none exists). See also username_exists.

This function is normally used when a user is registering, to ensure that the E-mail address the user is attempting to register with has not already been registered.

Usage

<?php
   
if( email_exists$email )) {
      
/* stuff to do when mail exists */
   
}
?>

Parameter

$email
(string) (required) The E-mail address to check
Default: None

Return

  • If the E-mail exists, function returns the ID of the user to whom the E-mail is registered.
  • If the E-mail does not exist, function returns false.

Examples

If the E-mail exists, echo the ID number to which the E-mail is registered. Otherwise, tell the viewer that it does not exist.

<?php
  $email = 'myemail@example.com';
  $exists = email_exists($email);
  if ( $exists )
    echo "That E-mail is registered to user number " . $exists;
  else
    echo "That E-mail doesn't belong to any registered users on this site";
?>

Notes

Change Log

Since: 2.1.0

Source File

email_exists() is located in wp-includes/user.php

Related

See also index of Function Reference and index of Template Tags.