bb_check_login

The BuddyPress bb check login function.

Description

bb_check_login( $user, $pass, (constant) $already_md5 = false ); 

Parameters (3)

0. $user
The user.
1. $pass
The pass.
2. $already_md5 — Optional. (constant) => false
The already md5.

Usage

  1. if ( !function_exists( 'bb_check_login' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-pluggable.php'; 
  3.  
  4. // The user. 
  5. $user = null; 
  6.  
  7. // The pass. 
  8. $pass = null; 
  9.  
  10. // The already md5. 
  11. $already_md5 = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bb_check_login($user, $pass, $already_md5); 
  15.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-pluggable.php  
  1. function bb_check_login($user, $pass, $already_md5 = false) { 
  2. global $wp_users_object; 
  3.  
  4. if ( !bb_get_option( 'email_login' ) || false === strpos( $user, '@' ) ) { // user_login 
  5. $user = $wp_users_object->get_user( $user, array( 'by' => 'login' ) ); 
  6. } else { // maybe an email 
  7. $email_user = $wp_users_object->get_user( $user, array( 'by' => 'email' ) ); 
  8. $user = $wp_users_object->get_user( $user, array( 'by' => 'login' ) ); 
  9. // 9 cases. each can be FALSE, USER, or WP_ERROR 
  10. if ( 
  11. ( !$email_user && $user ) // FALSE && USER, FALSE && WP_ERROR 
  12. || 
  13. ( is_wp_error( $email_user ) && $user && !is_wp_error( $user ) ) //WP_ERROR&& USER 
  14. ) { 
  15. // nope: it really was a user_login 
  16. // [sic]: use $user 
  17. } elseif ( 
  18. ( $email_user && !$user ) // USER && FALSE,WP_ERROR&& FALSE 
  19. || 
  20. ( $email_user && !is_wp_error( $email_user ) && is_wp_error( $user ) ) // USER && WP_ERROR 
  21. ) { 
  22. // yup: it was an email 
  23. $user =& $email_user; 
  24. } elseif ( !$email_user && !$user ) { // FALSE && FALSE 
  25. // Doesn't matter what it was: neither worked 
  26. return false; 
  27. } elseif ( is_wp_error( $email_user ) && is_wp_error( $user ) ) { //WP_ERROR&& WP_ERROR 
  28. // This can't happen. If it does, let's use the email error. It's probably "multiple matches", so maybe logging in with a username will work 
  29. $user =& $email_user; 
  30. } elseif ( $email_user && $user ) { // USER && USER 
  31. // both are user objects 
  32. if ( $email_user->ID == $user->ID ); // [sic]: they are the same, use $user 
  33. elseif ( bb_check_password($pass, $user->user_pass, $user->ID) ); // [sic]: use $user 
  34. elseif ( bb_check_password($pass, $email_user->user_pass, $email_user->ID) ) 
  35. $user =& $email_user; 
  36. } else { // This can't happen, that's all 9 cases. 
  37. // [sic]: use $user 
  38.  
  39. if ( !$user ) 
  40. return false; 
  41.  
  42. if ( is_wp_error($user) ) 
  43. return $user; 
  44.  
  45. if ( !bb_check_password($pass, $user->user_pass, $user->ID) ) 
  46. return false; 
  47.  
  48. // User is logging in for the first time, update their user_status to normal 
  49. if ( 1 == $user->user_status ) 
  50. bb_update_user_status( $user->ID, 0 ); 
  51.  
  52. return $user;