wp_authenticate_email_password

函数
wp_authenticate_email_password ( $user, $email, $password )
参数
  • (WP_User|WP_Error|null) $user WP_User or WP_Error object if a previous callback failed authentication.
    Required:
  • (string) $email Email address for authentication.
    Required:
  • (string) $password Password for authentication.
    Required:
返回值
  • (WP_User|WP_Error) WP_User on success, WP_Error on failure.
定义位置
相关方法
wp_authenticate_username_passwordwp_authenticate_application_passwordrest_get_authenticated_app_passwordwp_generate_passwordwp_authenticate
引入
4.5.0
弃用
-

wp_authenticate_email_password: 这个函数用来认证一个用户,给出他们的电子邮件地址和密码。

使用电子邮件和密码对用户进行认证。

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 ) ) {
			// Uses 'empty_username' for back-compat with wp_signon().
			$error->add( 'empty_username', __( '<strong>Error:</strong> The email field is empty.' ) );
		}

		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',
			__( 'Unknown email address. Check again or try your username.' )
		);
	}

	/** 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;
}

常见问题

FAQs
查看更多 >