使用电子邮件和密码对用户进行身份验证。

原型

wp_authenticate_email_password( WP_User|WP_Error|null $user, string $email, string $password )

参数

$user (WP_User|WP_Error|null) (Required) 如果先前的回调验证失败,则为WP_User或WP_Error对象。

$email (string) (Required) 验证的电子邮件地址。

$password (string) (Required) 验证密码。

返回值

(WP_User|WP_Error)  

源文件

路径:wp-includes/user.php

<?php
...
function wp_authenticate_email_password( $user, $email, $password ) {
	if ( $user instanceof WP_User ) {
		return $user;
	}
	if ( empty( $email ) || empty( $password ) ) {
		if ( is_wp_error( $user ) ) {
			return $user;
		}
		$error = new WP_Error();
		if ( empty( $email ) ) {
			$error->add( 'empty_username', __( '<strong>ERROR</strong>: The email field is empty.' ) ); // Uses 'empty_username' for back-compat with wp_signon()
		}
		if ( empty( $password ) ) {
			$error->add( 'empty_password', __( '<strong>ERROR</strong>: The password field is empty.' ) );
		}
		return $error;
	}
	if ( ! is_email( $email ) ) {
		return $user;
	}
	$user = get_user_by( 'email', $email );
	if ( ! $user ) {
		return new WP_Error( 'invalid_email',
			__( '<strong>ERROR</strong>: Invalid email address.' ) .
			' <a href="' . wp_lostpassword_url() . '">' .
			__( 'Lost your password?' ) .
			'</a>'
		);
	}
	/** This filter is documented in wp-includes/user.php */
	$user = apply_filters( 'wp_authenticate_user', $user, $password );
	if ( is_wp_error( $user ) ) {
		return $user;
	}
	if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) {
		return new WP_Error( 'incorrect_password',
			sprintf(
				/* translators: %s: email address */
				__( '<strong>ERROR</strong>: The password you entered for the email address %s is incorrect.' ),
				'<strong>' . $email . '</strong>'
			) .
			' <a href="' . wp_lostpassword_url() . '">' .
			__( 'Lost your password?' ) .
			'</a>'
		);
	}
	return $user;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_authenticate_email_password/