Support » Plugin: Simple Facebook Connect » [Plugin: Simple Facebook Connect] detect if user already pressed "like"

  • Resolved Mardie



    Is there a way that you can detect if the user already “liked” or “shared” your page?

    I know in facebook fbml there’s a simple code to do that:

    But the code above is not applicable to wordpress.

    Any idea? thanks

Viewing 15 replies - 1 through 15 (of 18 total)
  • Mardie


    or how to know if user already “liked” your page?

    Plugin Author Samuel Wood (Otto)

    (@otto42) Admin

    You can use the sfc_is_fan() function to determine if a viewer is a fan of your FB Application or Fan Page.

    But that won’t return true if they “liked” one of the posts on your site, or if they shared it. It only returns true if they’re a fan of your FB App/Page as a whole. This is what the “Like” button in the Fan Box/Like Box does, makes them like your area on Facebook.



    I really did not know where to start at first but thanks so much for the idea Otto! it worked! 🙂

    sfc_is_fan() doesn’t seem to work with the latest version. Can you point me in the right direction to detect if a WP user is a Fan of a Page, not an App?

    Thanks in advance!

    Plugin Author Samuel Wood (Otto)

    (@otto42) Admin

    Never got around to fixing up that function before releasing 1.0. Just now fixed it up, you can find the updated function in the trunk’s sfc-base.php:

    Just use this new file and sfc_is_fan() should work again.

    Plugin Author Samuel Wood (Otto)

    (@otto42) Admin

    Also note that like its predecessor, the sfc_is_fan() function has to make a call to Facebook’s servers to determine if the user is a fan. So it may be slow, since it’s making an external request. Therefore it wouldn’t be a good idea to use it on every page load, but perhaps only for specific use-cases.

    Awesome, Thank you for you quick response! Perhaps checking for a fan, then storing the info for the session? Still testing so I don’t use it for every page load.

    I found this on a blog that I thought I’d share as well. Thoughts?

    $request = $_REQUEST["signed_request"];
    list($encoded_sig, $load) = explode('.', $request, 2);
    $fbData = json_decode(base64_decode(strtr($load, '-_', '+/')), true);
    if (!empty($fbData["page"]["liked"]))
    { ?>
    You are a fan - insert html here
    <?php } else { ?>
    You are not a fan - insert html here
    <?php }
    Plugin Author Samuel Wood (Otto)

    (@otto42) Admin

    No, that’s a special case code. He’s using that for a page that’s running inside the Facebook canvas. Different situation.


    Hi how would you call this function?

    I want to show a fan-only offer on my WordPress site. Do the users have to actually connect with my site first for this to work or will it work if they are just logged in to Facebook.

    IE. if someone has liked my page before but hasn’t visited my site then they should be shown the fan content because they are a Facebook fan.


    Plugin Author Samuel Wood (Otto)

    (@otto42) Admin

    If they have never connected with your site, then your site has no way to know who they are and whether they are a fan or not.

    They have to connect at least once for the site to know their Facebook ID and thus be able to tell if they’re a fan.

    i thought so! would there be any way around this? i am building a mini-site using wordpress which is connected to an app on Facebook, so most users will viewing the site through the Facebook Page and be clicking the Like button on Facebook.

    Would there be anyway to connect them? There are plugins out there that integrate “reveal tabs” but only on a tab by tab basis, not site wide.

    Would you quote on creating something like that?

    Plugin Author Samuel Wood (Otto)

    (@otto42) Admin

    I assume you mean that you’re making a Canvas application of some sort? So that the website is visible to the user on a Facebook Page itself, in an iframe?

    In such a case, you still have to get the user to authorize the application in order to know who they are. This is talked about in the Authorization bit of

    Now, SFC doesn’t have any code specifically to handle Canvas applications. It’s more geared towards building FB connectivity into your own site. If you’re making a Canvas app, you’ll probably want to use some custom code instead. However, some of the bits of SFC would be suitable for lifting out and using in your custom code. The registration (and base) plugin has some code to handle the signed_request, for example. You’d likely have to rework it to your specific needs though.

    I am making a custom Facebook welcome page for a Facebook business page. Outside of WordPress it’s easy, just create an index.php file and call the facebook.php file from the PHP SDK then you can use the $like_status variable to show fan and non-fan content.

    AKA reveal tab – this might help explain what I mean:

    Plugin Author Samuel Wood (Otto)

    (@otto42) Admin

    ellebillias: It’s just as easy inside WordPress too, my point however was that SFC isn’t made to do that sort of thing. It doesn’t have any code to help create Canvas pages.

    On a Canvas page, you get different inputs than you do on non-Canvas pages. When your page is running inside Facebook, you get inputs from Facebook. Outside Facebook, you don’t get those inputs. You don’t have access to Facebook’s cookies. That sort of thing.

    A canvas page runs in the Facebook domain. SFC is designed to run on WordPress sites not in the Facebook domain.

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘[Plugin: Simple Facebook Connect] detect if user already pressed "like"’ is closed to new replies.