判断邮箱地址是否已经被注册过
描述
该函数判断所给电子邮件地址($email)是否已被某一用户名注册,并返回用户编号(邮件地址不存在则返回false)。参见username_exists.
用法
<?php
if( email_exists( $email )) {
/* stuff to do when email address exists */
}
?>
示例
<?php
$email = ‘[email protected]’;
$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”;
?>
历史
添加于 版本: 2.1.0
源文件
email_exists() 函数的代码位于 wp-includes/user.php
/**
* Checks whether the given email exists.
*
* @since 2.1.0
*
* @param string $email Email.
* @return int|false The user’s ID on success, and false on failure.
*/
function email_exists( $email ) {
if ( $user = get_user_by( ’email’, $email) ) {
return $user->ID;
}
return false;
}