I'm writing a plugin for Wordpress that required the Facebook PHP SDK. I've run into what I think is a common problem judging from the number of results I've found dating back to over a year ago. Unfortunately, I have been unable to find a solution.

I'm using Wordpress 3.8 and Facebook PHP SDK Master taken from github so this should be the latest version. I've actually run this same code outside of Wordpress and it successfully ran with no errors.

So, i upload my plugin and activate it. I go to the panel I've built that asks for the appID and Secret key and also the username for the facebook account. All the plugin will do is grab the username me feed.

So, when i try to run the primary function that loads the feed I get the following errors:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at {path}/wp-admin/includes/template.php:1698) in {path}/wp-content/plugins/{mypluginname}/facebook-php-sdk/src/facebook.php on line 48

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at {path}/wp-admin/includes/template.php:1698) in {path}/wp-content/plugins/{mypluginname}/facebook-php-sdk/src/facebook.php on line 48

What I've tried

So, I've read in a few different posts that I should use ob_start() and ob_end_flush() php functions and that will fix the problem. As i understand the problem I am having I am sending things to the header where I shouldnt because the header has already been sent.

I've tried ob_start / ob_end_flush at the top and bottom of my plugin and it made no different.

I've tried downloading the Facebook wordpress plugin and using the modified Facebook PHP SDK that that plugin uses and that got rid of those errors but created a new error.

Fatal error: Access to undeclared static property: WP_BaseFacebook::$CURL_OPTS in {path}/wp-content/plugins/{pluginname}/facebook-php-sdk/src/base_facebook.php on line 932

So, I read that this is because CURL is not enabled. I've checked my PHP INFO page and CURL is enabled. I use curl requests in another plugin. I do see certain things under the CURL features that are not enabled. Does anyone know which option I need to enable to get this modified version of the Facebook PHP SDK to work with my plugin?

Does anyone know how to fix either the errors I am getting from the standard Facebook PHP SDK OR does someone know how to fix the errors I am getting from modified Facebook PHP SDK?

Thanks in advance. I hope to get a solution to both worked and then finally put this issue to rest. We've been plagued with this same problem since 2011.

In order to provide some more details, here is part of the code I have in my plugin.


global $facebook; // read that i needed to add this line to my script; it didnt help.

// Create our Application instance (replace this with your appId and secret).
$fb_config = array(
  'appId'  => $ijFaceFeedAppID,
  'secret' => $ijFaceFeedSecretKey,
  'fileUpload' => false,
  'allowSignedRequest' => false

// get feed
$facebook = new WP_Facebook($fb_config); // am using the modified facebook sdk
$page_feed = $facebook->api(
  • The Facebook PHP SDK is a crap. Use the javascript version.
    – Chris_O
    Commented Dec 14, 2013 at 11:06
  • I'm not sure if i can use javascript for what i am trying to do. I'm pulling the feed in and them importing it into a database and then i use a wordpress shortcode to display the message on my website. I can see there are issue with the Facebook PHP SDK. Hopefully they improve it.
    – Robbiegod
    Commented Dec 14, 2013 at 16:30
  • As-written, this question involves PHP server configuration and a non-WordPress-specific PHP script, and is therefore off topic for WPSE. Please edit your question to clarify how it is specific to WordPress. Commented Dec 18, 2013 at 19:31
  • I'm writing a wordpress plugin that uses the Facebook PHP SDK. I'm running into the problem only when I put the Facebook PHP SDK into my Wordpress plugin. The code runs fine outside of the plugin as i have tested it. I believe I am correct in asking my question in the Wordpress section since the problem only occurs when it is wrapped into a wordpress plugin that I am writing. I was hoping that maybe other who are authoring Wordpress plugins would be able to offer some help getting the Facebook PHP SDK to work inside of a wordpress plugin. I think i make that clear in the question. Thanks.
    – Robbiegod
    Commented Dec 19, 2013 at 14:26

2 Answers 2


First of all download the zip of facebook php sdk from Facebook PHP SDK from Github.com

Extract the zip folder, you need only the 'src' folder for integrate your facebook application in your plugin.

copy the 'src' folder and paste it in your plugin directory.

In your plugin installer file, first start your session by writting session_start() and then include the facebook.php file from src folder. Like this:

session_start(); include('src/facebook.php');

Now follow the below code.


$config = array('appId' => 'Your APP ID', 'secret'=> 'Your App Secret');

$connect = new Facebook($config);

$user = $connect->getUser();
$me = null;

         $me = $connect->api('/me');
    catch(FacebookApiException $e)
        echo $e->getMessage();

    $logoutUrl = $connect->getLogoutUrl();
    echo "Logout";
    //as the facebook php sdk version is 3 so there is some change for permissions
    // If you want to add permission for read_streams so that pass array with login url
    $params = array('scope'=>'read_stream');
    $loginUrl = $connect->getLoginUrl($params);
    echo "Login";

Now you can login with facebook and asks for permission for read stream for first time only.

  • ok, thank you for your answer. I will try this out. I might have been missing the session_start(); line in the plugin.
    – Robbiegod
    Commented Dec 19, 2013 at 14:29
  • I tried your complete code in my plugin but i am still getting errors.
    – Robbiegod
    Commented Dec 19, 2013 at 15:59
  • Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent Is there a special place or function that i need to put the facebook sdk calls inside of my plugin? Currently, I have a function setup to get the "me" feed from Facebook. I'm adding that call as a link in the admin left menu so when I click that link from the wordpress menu it tried to reach out the facebook feed. I'm getting these header errors.
    – Robbiegod
    Commented Dec 19, 2013 at 16:04
  • i just tried putting session_start() as the first line of my plugin, that removed the error. I think that may have solved the header error problems. Question now is is that the best place in the plugin to put the session_start() function?
    – Robbiegod
    Commented Dec 19, 2013 at 16:08

Special Thanks @Azhar Munshi very much I faced the same problem but now after I've Tried to put session_start(); before include('src/facebook.php'); the errors disappear :)

  • use ob_start() next to session_start()
    – Balas
    Commented Dec 30, 2013 at 8:06
  • i did not need to put ob_start() before session_start() and it seems to work just fine. I had seen others using ob_start() too, but can u elaborate why that is the better option vs. just using session_start() by itself?
    – Robbiegod
    Commented Dec 30, 2013 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.