fb_login_validate

The Facebook Login Widget fb login validate function.

Description

fb_login_validate(); 

Usage

  1. if ( !function_exists( 'fb_login_validate' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'facebook-login-widget/login_afo_widget.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = fb_login_validate(); 
  7.  

Defined (1)

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

/login_afo_widget.php  
  1. function fb_login_validate() { 
  2. if(isset($_POST['option']) and sanitize_text_field($_POST['option']) == "afo_user_login") { 
  3. global $post; 
  4. if($_POST['user_username'] != "" and $_POST['user_password'] != "") { 
  5. $creds = array(); 
  6. $creds['user_login'] = sanitize_text_field($_POST['user_username']); 
  7. $creds['user_password'] = sanitize_text_field($_POST['user_password']); 
  8. $creds['remember'] = true; 
  9.  
  10. $user = wp_signon( $creds, true ); 
  11. if($user->ID == "") { 
  12. $_SESSION['msg_class'] = 'error_wid_login'; 
  13. $_SESSION['msg'] = __($user->get_error_message(), 'facebook-login-afo'); 
  14. } else{ 
  15. wp_set_auth_cookie($user->ID); 
  16. wp_redirect( site_url() ); 
  17. exit; 
  18. } else { 
  19. $_SESSION['msg_class'] = 'error_wid_login'; 
  20. $_SESSION['msg'] = __('Username or password is empty!', 'facebook-login-afo'); 
  21.  
  22.  
  23.  
  24. if(isset($_REQUEST['option']) and sanitize_text_field($_REQUEST['option']) == "fblogin") { 
  25. global $wpdb; 
  26. $appid = get_option('afo_fb_app_id'); 
  27. $appsecret = get_option('afo_fb_app_secret'); 
  28. $facebook = new Facebook(array( 
  29. 'appId' => $appid,  
  30. 'secret' => $appsecret,  
  31. 'cookie' => TRUE,  
  32. )); 
  33. $fbuser = $facebook->getUser(); 
  34. if ($fbuser) { 
  35. try { 
  36. $user_profile = $facebook->api('/me'); 
  37. catch (Exception $e) { 
  38. echo $e->getMessage(); 
  39. exit(); 
  40. $user_fbid = $fbuser; 
  41. $user_email = $user_profile["email"]; 
  42.  
  43. if($user_email == '') { 
  44. $user_email = $user_fbid.'@facebook.com'; 
  45.  
  46. if( email_exists( $user_email )) { // user is a member  
  47. $user = get_user_by('login', $user_email ); 
  48. $user_id = $user->ID; 
  49. wp_set_auth_cookie( $user_id, true ); 
  50. } else { // this user is a guest 
  51. $random_password = wp_generate_password( 10, false ); 
  52. $newuserdata = array( 
  53. 'user_login' => $user_email,  
  54. 'user_email' => $user_email,  
  55. 'user_pass' => $random_password 
  56. ); 
  57. $user_id = wp_insert_user( $newuserdata ); 
  58. wp_set_auth_cookie( $user_id, true ); 
  59.  
  60. wp_redirect( site_url() ); 
  61. exit; 
  62.  
  63. }