Easier way to add facebook connect to your blog using WP-FacebookConnect plugin

Please wait

fconnectwp

Previously I’ve written about how to add facebook connect to your wordpress blog but that plugin requires heavy modification on the comments.php file, which is in a way pretty tough for most people to do. So I’ve taken consideration to use the WP-FacebookConnect plugin which is featured in facebook developers wiki. It requires much more simpler method to add facebook authorization connectivity to your blog. I’ve seen Chris Wallace already had a helpful and simple explanation on this. So I will just compliment his article and add some extras to you don’t need to go to so many other websites to accomplish the integration with facebook.

Get 5GB Free Space on the Cloud for your Devices

Basically you need these steps to complete:

  1. Create your Facebook Application and get the API and secret keys
  2. Download and Install the officially listed WP-FaceBook connect plugin
  3. Configure the plugin and add your API and secret keys and save the options
  4. Now your WP theme folder, open the comments.php file in you favorite editor and look for the comment form element and add this piece of code where you want the Facebook Connect button to appear. Here is the piece of code
  5. Here is the code inside my comments.php near to the comments form

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <form action="<?php echo get_settings('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
        <?php if ( $user_ID ) : ?>


      <p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out &raquo;</a>

        <?php else : ?>
    <?php do_action('fbc_display_login_button'); ?>
      <p>
        <?php
        echo "<small>Note: <acronym title="Facebook is a Social Networking Engine">Facebook</acronym> users doesn't require to fill up name, e-mail, website or captcha code</small><br>";
        echo "Already a Member? <br>";
        echo '<a href="'.get_option('siteurl').'/wp-login.php'.'"><b>Login..</b></a> or<br/>';
        ?>
  6. Yes it’s as simple as that, but in-case it doesn’t work on IE or any CSS problems you can check this official faq

WP-SuperCache Fix for Wp-FacebookConnect

Now those who are using WP-SuperCache, here is the solution for you guys. Basically you need to do some .htaccess mod re-write and a small plugin for WP-SuperCache.

There are two places that WP Super Cache looks at for filtering user cookies (taken from AllFaceBook). The first (which I assume is the case for most users) is in the .htaccess file in your document root. If this is how your site is configured, you’ll need to find the following code in your .htaccess file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# BEGIN WPSuperCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]

RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
</IfModule>
# END WPSuperCache

All you need to do at that point is replace the two RewriteCond %{HTTP:Cookie} lines with the following:

1
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_|YOURAPIKEY_user).*$

Now create a file fbconnect.php (It can be any name with an extension .php). Copy paste the following code inside the file and save it.

1
2
3
4
5
6
7
8
9
<?php
// provided by Nick ONeil
function fbc_supercache($cachestr){
   if(isset($_COOKIE["YOURAPIKEY_user"]) )
      $cachestr .= $_COOKIE["YOURAPIKEY_user"];
   return $cachestr;
}
add_cacheaction('wp_cache_get_cookies_values', ‘fbc_supercache');
?>

Replace "YOURAPIKEY" with your actual API key and save it in the folder /wp-content/wp-plugins/wp-super-cache/plugins/. Upload that to your server and you should be good to go!

Thank you very much Nick ONeil from AllFacebook.com & Chris Wallace. There are actually few other tutorials about integrating the facebook connect, feel free to browse them too.

CSS Customization

The css that comes with WP-FacebookConnect is of really NO use, Chris Wallace already written a nice CSS override to the article so I am taking it from him for sharing purpose. The CSS file you need to modify is inside the plugin folder (fbconnect.css).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Facebook Connect Styles by Chris Wallace */

.facebook-connect{ /* I added this div wrapper myself, was not part of the plugin */
  position: relative;
  float: right;
  width: 300px;
  margin-top: -65px;
  text-align: right
}

.facebook-connect a,  /* you probably won't need this css */
.facebook-connect a:hover,
.facebook-connect a img,
.facebook-connect a:hover img{
  border: 0
}

.facebook-connect .fbc_connect_button_area { /* This is the button container for your comment form */
  border: 0;
  float:none;
  margin:0;
  padding:0
}

body .fbc_profile_header { /* I added body to override the CSS from Facebook Connect's default CSS */
  background:#000000;
  border:1px solid #3d3e3d;
  border-right: 0;
  padding:10px 5px 5px 10px;
  position:fixed; top: 45%; right:0;
  text-align:left;
  width:220px
}

body .fbc_profile_header a.logout{ /* this is a custom class I added to the HTML in fbconnect.php */
  font-size: .9em;
  color: #999
}

Also let me know whether this helped you out or not or are you facing any specific problems?

About Ruhani Rabin

Ruhani Rabin is the original owner and author of this blog. He also reviews web 2.0 startups at Tech2all.com. Largely interested in web 2.0 apps & Social Media. Currently the Vice President of MOL Access Portal (MOL is owner of Friendster.com). Also he is Web 2.0 & Social Media Researcher and a Total fun Geek!.. There you have it ;)

Facebook Comments

  • http://twitter.com/j0lliyo njalk

    Tahnk you! Exactly what I was looking for!

  • http://twitter.com/BarryinCrete Barry Rodgers

    Correct me if I am wrong, but this is just so people can comment o n the blog.

    How do I integrate FB connect to allow people to become subscribers of the blog?

  • Tardis

    Dear Bloggers. I have a problem. I use 3.0.5 WordPress with Facebook plugin and wp super cache plugin. My problem is: whenever WP supercache active, the login is not perfect. Sometimes even if i’m logged in it doesn’t write. Bigger problem: after i copy the fbconnect.php file into the WP supercache/plugin directory my webpage will be white. No error message no announcement. Just white page. Thanks your help

  • Tamargenger

    Thank you for writing this, but i still can’t get the comments to work. I copy and pasted the above code, but I don’t know exactly where in the comments.php – do I delete anything or just put this in. When I have done it I end up with this error ont he front: Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in D:Hosting5855845htmlblogwp-contentthemesthis-just-incomments.php on line 93
    and it takes away my sidebar. Please help.

    • bjarkehs

      The line: echo “Note: Facebook users doesn’t require to fill up name, e-mail, website or captcha code”; is not good. Since the php sentence uses the “” thus the html ones around “Facebook is a Social Networking Engine” should be replaced by single quotes ‘ ‘

  • http://forexhug.com forexhug

    thanx i already use this plugin my autoblogs

  • http://twitter.com/ShankerBakshi Shanker Bakshi

    I can see these days lots of blog with facebook comment post ability, would like you to cover that, sorry if you already said that and i missed it somewhere.

  • http://twitter.com/bmdisease bigmentaldisease

    Helpful

  • Visitor

    this is a great plugin, I just have an issue the logout with redirect doesn’t work when a user is login into facebook. what can I do to fix the issue?

    thans for your help

  • http://twitter.com/thewxobserver Richard Foreman

    Great plugin but I have tried everything to move the profile window from the top corner. It is behind my twitter and facebook buttons on the site. Anything to help out. http://www.theweatherobserver.com

  • pepe100

    how..

  • Pingback: Facebook connect On Wordpress | zeez0ne [dot] info

  • Pingback: Easier way to add facebook connect to your wordpress blog using WP-FacebookConnect plugin, fast and easy Integration [WordPress] | WpMash - WordPress News

  • http://twitter.com/0time 0time

    How to do this?

  • Anirban

    Hello Ruhani,

    I tried implementing this plugin. After some stumbling and all I finally got the plugin activated. But, in the code I see that the API key needs to be entered into a form. I'm not getting any form or setting option at the admin panel. What to do or where the API keys need to be entered? Please advise.

    Regards,

    Anirban.

  • http://www.google.com/profiles/techiezine Mark

    Any ideas on how to set the default user role?

    As it ignored what I've set as deafult user role.

    :-(

    Thanks

  • http://www.facebook.com/pages/Which-Team-Will-Win-the-2010-World-Cup/107799649266632 World Cup Fever

    Thanks for this one. I'm sure it will make someone happy. If you don't mind, can you share on how to create a facebook apps if we know nothing about it?

  • http://www.inkatechnology.co.uk/facebook-connect-integration-api.php Facebook Connet Site

    Thanks for the tips on clearing the FB cookies, that was giving me some issues and I was looking for the right things to call. Thanks again.

  • http://www.ruhanirabin.com/ Ruhani Rabin

    The demo site already real as much it could be

  • http://www.facebook.com/people/Ed-ONeill/1081965643 Ed ONeill

    Wanted to see this working on a real site. Having problems with my implementation.

  • Pingback: wp-popular.com » Blog Archive » Easier way to add facebook connect to your wordpress blog using WP-FacebookConnect plugin, fast and easy Integration [WordPress]

  • http://gisnap.com gisnap

    Its really cool, I came to know this really worth visiting, just bookmarked your site.

    http://gisnap.com/
    The place where fun never ends

  • manishfusion

    hey it's really awesome no word for this type of picture hmmm keep rocking thanks you so much :)

    best deals

  • http://www.facebook.com/ashrith.gizmofreak Ashrith Josephite

    really wanted dis…tnx

  • http://www.facebook.com/andreapinti Andrea Pinti

    Thanks for this post, its really helpfull

  • max191

    It seems that you are maintaining a steady blogging pace. Well done! Looking for more updates from your end. Thanks a lot!
    regards
    charcoal grill

  • http://gadgetgeek.blogsome.com/ Jeff

    Thanks for sharing such a wonderful bridge script.

  • Pingback: My Alpha Geek » Blog Archive » FB-Connect integration with Wordpress

  • http://en-gb.facebook.com/afcol Afc Ovidiu Lapusneanu

    nice work

  • http://twitter.com/eliminat eliminat

    Any tips on doing this while still allowing the OpenID plugin to work? If I enable this plugin I can no longer login anywhere with my URL.

  • http://www.facebook.com/profile.php?id=611825537 facebook-611825537

    Thanks for the post ;)

  • http://www.linuxforu.com Linux For You

    d00d, I just couldn't manage to get the FB Connect button (and the link) working on my site. Any idea if that might be a known issue?

  • http://www.linuxforu.com Linux For You

    d00d, I just couldn't manage to get the FB Connect button (and the link) working on my site. Any idea if that might be a known issue?

  • http://www.ruhanirabin.com Ruhani Rabin

    I moved to disqus on late february due to the caching problems with facebook
    plugin. IntenseDebate is good but not supporting login via twitter or
    facebook. Thats why i choose Disqus instead :)

  • http://www.benway.net benwaynet

    This post was from January, when did you move to disqus? Why disque instead of intense debate?

  • http://www.facebook.com/people/Saurav-Dhar/44404868 Saurav Dhar

    This is cool

  • http://www.socialium.com/ Facebook Applications

    I just recently discovered your site and appreciate you sharing your bout with facebook application development with the world.but this site also search best knowledge facebook application development.
    <a href=”http://www.socialium.com/
    “>http://www.socialium.com/

  • http://www.facebook.com/people/Gerome-Freeman/830307377 Gerome Freeman

    test

  • http://www.facebook.com/people/Pj-De-Best/541276078 Pj De Best

    Thanks for that. Great stuff

  • http://id-id.facebook.com/people/Oscar-Kurniawan-Oz/635423657 Oscar Kurniawan Oz

    Hi…

    i'd like to make a modification for this plugin. i want to make it like google friend connect member badges and hard-code it in the theme not in the widget. can you help me?

  • http://www.ruhanirabin.com Ruhani Rabin

    I believe the plugin is designed for PHP5 and above.. Can you check which version of PHP you are running?

  • OKRealtorJenn

    Hi Ruhani!

    Thank you for your helpful hints.

    However when I installed the WP-Facebook Connect Plugin and tried to install… I received this error.

    Parse error: parse error, unexpected T_OBJECT_OPERATOR in /home/content/j/o/h/johnkerberpda/html/jenn/wp-content/plugins/wp-facebookconnect/fbconnect.php on line 38

    Do you have any helpful suggestions?

    Thanks!!!

  • http://www.facebook.com/people/Nisar-Ahmad/692531435 Nisar Ahmad

    dgfsafsdf fsdfsdf connect

  • http://www.iandavidchapman.com ian david chapman

    For an even easier solution that requires no coding check out this post

    http://www.iandavidchapman.com/how-to-add-faceb…

  • http://www.facebook.com/people/Syed-M-Ruhani-Rabin/664895507 Syed M. Ruhani Rabin

    and all of them works

  • http://www.facebook.com/people/Syed-M-Ruhani-Rabin/664895507 Syed M. Ruhani Rabin

    hi, thanks for pointing out the problem with the callback url. Having said that I've tried 3 mechanism to connect using facebook, including comments publishing to facebook wall.

  • http://blogjunkie.net blogjunkie

    Hi Ruhani, I think both your tutorials don't address the Facebook iFrame window which is supposed to appear and asks if you would like to publish your comment to Facebook.

    I've implemented this WP-FacebookConnect plugin on my blog and it doesn't send my comments to Facebook. Have you verified that it works?

    Also, your Facebook Connect implementation is a bit broken. Here's what I get when I tried to login with Connect:

    Invalid Argument

    The Facebook Connect cross-domain receiver URL (http://disqus.com/facebook-connect/xd_receiver….) must have the application's callback url (http://www.ruhanirabin.com/wp-content/plugins/w…) as a prefix. You can configure the callback url in the application's settings.

  • http://www.ruhanirabin.com Ruhani Rabin

    Hi @Nik, if you've changed your domain name, you need need to update the facebook application as well. Otherwise it wont work at all. By the way I've written an implementation on the plug-in http://www.ruhanirabin.com/integrate-social-net… which is using the plugin from sociable.es . that plugin has issues with my caching engine (which i need to keep this site healthy) other than that its a great plugin.

    So first of all update all the information about the new domain name in your facebook application.

    Secondly go to admin panel for the plugin and try to update the info over there once again.

    Let me know

  • http://unearthingasia.com Nik

    Hi Ruhani,

    Thanks for the help, but I'm actually trying to get Facebook Connect to work with a different plugin, this one here: http://www.sociable.es/facebook-connect/

    The reason I want to use that is .. well first off it was much easier .. and second is it adds this neat little widget that allows your visitors to login, and people will be able to see who has logged onto Facebook Connect on your site.

    So it was working like a charm till today when I decided to switch my domain name. Boom. It just stopped working. The “logout” now does nothing. The “invite” does nothing. The photo of visitors now appears vertically, making it a tall, long, ugly box.

    I'm really … not sure where to turn for help. Any ideas would be GREATLY appreciated. Cheers.

    -Nik

  • Pingback: How to integrate social networking in wordpress using facebook connect api and wordpress plugin [Tutorial] | Ruhani Rabin