wppaste
WordPress

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

Since
4.5.0
Source
wp-includes/user.php:242
Authenticates a user using the email and password.

Parameters

$userWP_User|WP_Error|null
WP_User or WP_Error object if a previous callback failed authentication.
$emailstring
Email address for authentication.
$passwordstring
Password for authentication.

Return

WP_User|WP_Error
WP_User on success, WP_Error on failure.

Cost profile

Measured from the compiled opcodes, not from a stopwatch. Every number here is identical on any machine that runs the same PHP version, and every function in core is ranked by these figures.

Cost class
Heavy

Reaches the database via get_user_by().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
6–67

Executed per call on PHP 8.4, depending on the branch taken. The body compiles to 121.

Plugin surface
1 hook

Third-party callbacks on 'wp_authenticate_user' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_user_by()called directly
  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach option, cache, serialize and transient those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 10 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_authenticate_email_password() can have, taken from its control-flow graph on PHP 8.4.

WhenInstructionsCalls it makes
$user instanceof6none
!($user instanceof)12–21is_wp_error()
!($user instanceof) && !empty($email) && !empty($password) && !is_email()14is_email()
!($user instanceof) && !is_wp_error()26–28is_wp_error()__()->add()
!($user instanceof) && !empty($email) && !empty($password) && is_email()27is_email()get_user_by()__()
!($user instanceof) && !empty($email) && !empty($password) && is_email() && is_wp_error()30is_email()get_user_by()apply_filters()is_wp_error()
!($user instanceof) && empty($email) && !is_wp_error() && empty($password)33–35is_wp_error()__()->add()__()->add()
!($user instanceof) && !empty($email) && !empty($password) && is_email() && !is_wp_error() && !wp_password_needs_rehash()50is_email()get_user_by()apply_filters()is_wp_error()wp_check_password()wp_password_needs_rehash()
!($user instanceof) && !empty($email) && !empty($password) && is_email() && !is_wp_error() && wp_password_needs_rehash()56is_email()get_user_by()apply_filters()is_wp_error()wp_check_password()wp_password_needs_rehash()wp_set_password()
!($user instanceof) && !empty($email) && !empty($password) && is_email() && !is_wp_error()67is_email()get_user_by()apply_filters()is_wp_error()wp_check_password()__()esc_html()sprintf()wp_lostpassword_url()__()

Across PHP versions

PHPCompiledExecutedBranchesNotes
7.41216–6711Compiles to the same instructions
8.11216–6711Compiles to the same instructions
8.21216–6711Compiles to the same instructions
8.31216–6711Compiles to the same instructions
8.41216–6711Compiles to the same instructions

Oldest PHP that compiles this body: 7.4. An instruction is not a fixed amount of time, so a version with the same count is not necessarily the same speed; what the count rules out is a difference in the work itself.

Hooks fired · 1

One hook fires while wp_authenticate_email_password() runs, in this order:

  1. apply_filters( wp_authenticate_user )filterline 285 (+43 into the body)

    Filters whether the given user can be authenticated with the provided password.

Uses · 11

Source

function wp_authenticate_email_password(	$user,	$email,	#[\SensitiveParameter]	$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;	} 	$valid = wp_check_password( $password, $user->user_pass, $user->ID ); 	if ( ! $valid ) {		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>' . esc_html( $email ) . '</strong>'			) .			' <a href="' . wp_lostpassword_url() . '">' .			__( 'Lost your password?' ) .			'</a>'		);	} 	if ( wp_password_needs_rehash( $user->user_pass, $user->ID ) ) {		wp_set_password( $password, $user->ID );	} 	return $user;}

History

Introduced in 4.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/user.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.