wp_login

Checks a users login information and logs them in if it checks out.

Description

wp_login( (string) $username, (string) $password, (string) $deprecated = '' ); 

This function is deprecated.

Use the global $error to get the reason why the login failed. If the username is blank, no error will be set, so assume blank username on that case.

Plugins extending this function should also provide the global $error and set what the error is, so that those checking the global for why there was a failure can utilize it later.

Parameters (3)

0. $username (string)
User's username
1. $password (string)
User's password
2. $deprecated — Optional. (string) => ''
The deprecated.

Usage

  1. if ( !function_exists( 'wp_login' ) ) { 
  2. require_once ABSPATH . WPINC . '/pluggable-deprecated.php'; 
  3.  
  4. // User's username 
  5. $username = ''; 
  6.  
  7. // User's password 
  8. $password = ''; 
  9.  
  10. // The deprecated. 
  11. $deprecated = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wp_login($username, $password, $deprecated); 
  15.  

Defined (1)

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

/wp-includes/pluggable-deprecated.php  
  1. function wp_login($username, $password, $deprecated = '') { 
  2. _deprecated_function( __FUNCTION__, '2.5.0', 'wp_signon()' ); 
  3. global $error; 
  4.  
  5. $user = wp_authenticate($username, $password); 
  6.  
  7. if ( ! is_wp_error($user) ) 
  8. return true; 
  9.  
  10. $error = $user->get_error_message(); 
  11. return false;