WordPress & Facebook – A way to integrate

Why WordPress + Facebook

WordPress is the fastest growing web application development platform. This will be used as application development framework more widely in the near future. Facebook is the third largest country in the world with over 700 million users and still growing. As the user login system has almost saturated, application developers started using Single Sign on with larger networks like facebook, google, twitter. I have chosen Facebook among them to explain how it can be integrated with WordPress login.

Facebook Registration and Login Plugins – How to

Facebook has released login and registration plugins for the websites.

http://developers.facebook.com/docs/plugins/registration/

This plugin allows the developer to add the fields that are in the Facebook and custom fields as well. redirect_uri is the URL where the data returned from FB can be stored (registration function of the website). This should be sent as an input variable with the registration.

<iframe src="http://www.facebook.com/plugins/registration.php? client_id=113869198637480& redirect_uri=http%3A%2F%2Fdevelopers.facebook.com%2Ftools%2Fecho%2F& fields=name,birthday,gender,location,email"

Coming to WordPress, a custom function should be created to register the details from FB into WP users table. To implement login, the following cases should be considered

  1. Login to WordPress system automatically when a user is logged in at Facebook
  2. Logout of WordPress (if you do not want the user to use your website without FB) when user logs out of facebook
  3. When the users wants to login to the website, login plugin (button) shall ask the user to log into facebook.

To implement the above cases, following best practices of facebook registration plugin should be useful.

Using JS SDK the user can be checked against facebook login every time when the website loads.

If the user is logged in the facebook, the ID and access token that is  should be sent to WordPress function through ajax. WordPress function should use graph social api to pull the data and verify it against the data received from JS SDK. If this matches user should be logged in to the WordPress system.

If the user is not logged in, a WordPress ajax function should be called by the Javascript to log the user out of WordPress.