wp_authenticate_email_password

Authenticates a user using the email and password.

Description

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

Returns (WP_User|WP_Error)

WP_User on success, WP_Error on failure.

Parameters (3)

0. $user (WP_User|WP_Error|null)
WP_User or WP_Error object if a previous callback failed authentication.
1. $email (string)
Email address for authentication.
2. $password (string)
Password for authentication.

Usage

  1. if ( !function_exists( 'wp_authenticate_email_password' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // WP_User or WP_Error object if a previous 
  5. // callback failed authentication. 
  6. $user = null; 
  7.  
  8. // Email address for authentication. 
  9. $email = ''; 
  10.  
  11. // Password for authentication. 
  12. $password = ''; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = wp_authenticate_email_password($user, $email, $password); 
  16.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/user.php  
  1. function wp_authenticate_email_password( $user, $email, $password ) { 
  2. if ( $user instanceof WP_User ) { 
  3. return $user; 
  4.  
  5. if ( empty( $email ) || empty( $password ) ) { 
  6. if ( is_wp_error( $user ) ) { 
  7. return $user; 
  8.  
  9. $error = new WP_Error(); 
  10.  
  11. if ( empty( $email ) ) { 
  12. $error->add( 'empty_username', __( '<strong>ERROR</strong>: The email field is empty.' ) ); // Uses 'empty_username' for back-compat with wp_signon() 
  13.  
  14. if ( empty( $password ) ) { 
  15. $error->add( 'empty_password', __( '<strong>ERROR</strong>: The password field is empty.' ) ); 
  16.  
  17. return $error; 
  18.  
  19. if ( ! is_email( $email ) ) { 
  20. return $user; 
  21.  
  22. $user = get_user_by( 'email', $email ); 
  23.  
  24. if ( ! $user ) { 
  25. return new WP_Error( 'invalid_email',  
  26. __( '<strong>ERROR</strong>: Invalid email address.' ) . 
  27. ' <a href="' . wp_lostpassword_url() . '">' . 
  28. __( 'Lost your password?' ) . 
  29. '</a>' 
  30. ); 
  31.  
  32. /** This filter is documented in wp-includes/user.php */ 
  33. $user = apply_filters( 'wp_authenticate_user', $user, $password ); 
  34.  
  35. if ( is_wp_error( $user ) ) { 
  36. return $user; 
  37.  
  38. if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { 
  39. return new WP_Error( 'incorrect_password',  
  40. sprintf( 
  41. /** translators: %s: email address */ 
  42. __( '<strong>ERROR</strong>: The password you entered for the email address %s is incorrect.' ),  
  43. '<strong>' . $email . '</strong>' 
  44. ) . 
  45. ' <a href="' . wp_lostpassword_url() . '">' . 
  46. __( 'Lost your password?' ) . 
  47. '</a>' 
  48. ); 
  49.  
  50. return $user;