email_exists()判断邮箱地址是否已经被注册过

目录

描述

译文

该函数判断所给电子邮件地址($email)是否已被某一用户名注册,并返回用户编号(邮件地址不存在则返回false)。参见username_exists.

原文

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.

email_exists() 描述

用法

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

email_exists() 用法

示例

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.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<?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";
?>

email_exists() 示例

历史

添加于 版本: 2.1.0

email_exists() 历史

源文件

email_exists() 函数的代码位于 wp-includes/user.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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;
}

email_exists() 源文件

相关