I am working on a custom function for login in my users via facebook.
I started by reading this nice tutorial on how to login in via facebook: http://digitalzoomstudio.net/2013/02/09/tutorial-how-to-login-via-facebook-in-your-wordpress-blog/
The function will log in the user to wordpress if an account with his/her facebook email already exists in the wordpress blog. If it doesnt exist, it will automatically create an account for the user.
Everything works as expected. However, I have an issue when login in and login out.
There is a "Login with Facebook" button. This button will change to Logout (this logout button is supposed to logout the user from facebook) if the user logged in.
One issue (LOGIN IN):
The first time the user clicks the "Login with facebook" button, the user is logged into the wordpress blog; however, Facebook API wont recognize the user thus making the facebook login button output a LOGIN button instead of a LOGOUT button.
The second time, the user clicks the LOGIN button, Facebook API DOES recognize the user and the button changes to LOGOUT.
So, why is it that the first time the user is not being recognized by facebook but the second time is?
The other issue is this (LOGIN OUT):
Once the user logs in the first time it hits the facebook LOGIN button, and wants to logout from my wordpress blog through a custom made logout button (this button is supposed to logout the user from the blog only and not from facebook), it works perfectly!
However, if the user has logged in by clicking the facebook LOGIN button a second time, the custom made logout button has to be clicked twice in order to logout the user successfully.
I know how to solve this partially. I could just check if the user is logged in the blog and remove the LOGIN button; however, I want to know why I am getting this strange behavior from facebook and how it is conflicting my blog.
For the second issue (when user logs out) I found the solution. I just had to destroy facebook session
UPDATE 2: SOLVED!
The tutorial from the link I provided was destroying the facebook session after login in and when creating a new account for some reason. I just had to remove
$facebook->destroySession(); from both parts and now everything is working as intended.