WordPress.org

Support

Support » Themes and Templates » Facebook SDK not working in wordpres template

Facebook SDK not working in wordpres template

  • Hi!

    I’m trying to implement the Facebook php sdk in a WordPress template, but I just can’t get it to work. The supplied example.php works without problems, but the same code in a template doesn’t. I boiled the problem down to the getSession() method, which simply always returns null.

    Since example.php works i figure the problem is somehow related to WordPress. I really can’t think of any reason why it shouldn’t work in WordPress.

    Any ideas?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I’ve found a temporary solution. In getSession() the following rows remove backslashes only if get_magic_quotes_gpc() is true:

    parse_str(trim(
       get_magic_quotes_gpc()
            ? stripslashes($_COOKIE[$cookieName])
            : $_COOKIE[$cookieName],
        '"'
    ), $session);

    However, for some reason backslashes in the cookie are added despite get_magic_quotes_gpc() being false. Thus changing the above rows to:

    parse_str(trim(
        stripslashes($_COOKIE[$cookieName]),
        '"'
    ), $session);

    solves the problem. I’m not sure though whether not not this creates any other problems.

    Hi tWH,

    Thank you for the finding. That solved my two days of agony.

    On my PHP install, “magic_quotes_gpc” is off by default. And it seems like it will be deprecated in future versions of PHP.

    I implemented a similar solution except that I check for it:

    parse_str(trim(
        function_exists( "get_magic_quotes_gpc" )
          ? stripslashes($_COOKIE[$cookieName])
          : $_COOKIE[$cookieName],
        '"'
      ), $session);

    That way the code is more portable for different environments where we simply can’t know the status of “get_magic_quotes_gpc”.

    Thanks again!

    Actually what I posted is not idea either.

    It turns out this is an issue with WordPress’ internal wp_magic_quotes() function screwing with facebook php-sdk.

    So what I did instead was to turn force turn on magic_quotes_gpc for wordpress only.

    To do that, at the root of WordPress director, create a .htaccess file (if there isn’t already one). And paste the follow code to force it on.

    php_flag magic_quotes_gpc on

    Cheers…

    tWH, thanks so much for the fix! I’ve spent the last two days trying to figure out why the cookie was correctly being set but the session was always null.

    I guess we’ll have to go with your hack until Facebook fixes this so it works correctly with WordPress.

    ~David

    I’m having the exact same issue! Thanks for coming up with a solution.

    Lothaire

    I’m having similar problems! But in my php.ini file magic quotes is set to on by default

    magic_quotes_gpc on

    what would I use to make the Facebook getSession() work on my WordPress?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Facebook SDK not working in wordpres template’ is closed to new replies.
Skip to toolbar