Support » Plugin: WPBook » [Plugin: WPBook] Cannot redeclare class FacebookApiException

  • Resolved O Ofutur


    It seems like a check needs to be put in place to make sure that the plugin doesn’t re-declare classes.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author John Eckman


    @olivier There already is one. Can you be more specific about the condition and where you are seeing the error?

    What other Facebook-related plugins are you running?

    Here’s what we use before loading the Facebook class:

    if(!class_exists('Facebook')) {
      include_once(WP_PLUGIN_DIR . '/wpbook/includes/client/facebook.php');

    Likely you’re using some other FB plugin which uses a different version of the Facebook client?

    Plugin Author John Eckman


    Maybe we need to change this to look for the class FacebookAPIException first, rather than just Facebook – though both are declared by the facebook.php sdk.

    Hello John,

    I’m indeed using other Facebook plugins, but the Fatal Error came from WPBook.
    It happened when publishing a new article.

    I’ve checked the code, and indeed, there are a couple of places where that check is in place, but none check for the FacebookApiException class.

    I’m too far from the action to be able to provide a fix at this time…

    I’ve disabled “Comments for Facebook” and will try to send the article to Facebook to see if it helps.

    Plugin Author John Eckman


    Both a “Facebook” class and a “FacebookApiException” class are declared by the version of the Facebook PHP SDK we’re using (2.1.2, for what it is worth).

    Older versions of the SDK may declare other classes – we check for the presence of the “Facebook” class.

    Which plugin throws the error really just depends on who hits that part of their code first.

    What version of Comments for Facebook are you using?

    Plugin Author John Eckman


    Looking at Comments for Facebook 3.1, it looks like they are using the same version of the Facebook SDK, so I am not sure what’s happening here.

    Maybe the trick is to check first if *both* Facebook and FacebookApiExtension have been defined?

    Plugin Author John Eckman


    D’oh, figured it out.

    In wp-content/plugins/wpbook/includes/publish_to_facebook.php, change line 9 from:
    if(!class_exists('FacebookRestClient')) {

    if(!class_exists('Facebook')) {

    This particular bit of code was checking for the *old* Facebook SDK, which had a FacebookRestClient class, not a Facebook class.

    I’ve checked in the change, and it will be part of the next release, or you can make a local change now.

    I see 🙂
    I saw that line and thought you needed to check for every class (Facebook, FacebookRestClient, FacebookApiException, etc.)

    Thanks for fixing this 🙂

    Jon Yoder


    I’ve recently run into the same problem. I’ve had the Facebook Comments and Wordbooker work together before, but now they aren’t working together.

    I’m getting this error:
    Fatal error: Cannot redeclare class FacebookApiException in /home/jonsite/www/blog/wp-content/plugins/wordbooker/fb2/base_facebook.php on line 101

    When I disable the Facebook Comments plugin, it works great. Do you know what the issue is? It seems like not many other people are having this problem as I can’t find too much about it online.

    Plugin Contributor Brooke.


    @darkshadowfor I think you may be confusing Wordbooker with WPBook. They are two completely different plugins. This is the support for WPBook.

    With that being said. Most of the time this problem is a result of trying to call two different versions of the Facebook class or trying to call the same version twice. I’m not sure which is the case here as I’m not that familiar with either plugin. You can search the plugin source for the class and compare versions and if they are the same use something like the if(!class_exists('Facebook')) { example above.

    Don’t worry – its probably my fault as I rolled the new FB PHP API SDK out with the new version of Wordbooker and its causing problems.

    Plugin Contributor Brooke.


    @steveatty I bet you are having the same problems that we are (we are also using the new FB API) which is that older or non-updated plugins are using the older FB API and they don’t play nice together. I guess on that plus side that means our plugins should work together now 🙂

    The new SDK does so many things wrong – like those silent fatals if curl or JSON support is missing, and then using the same class names across different versions of the SDK and never checking to see if they exist which then causes problems. Its a complete pain

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Plugin: WPBook] Cannot redeclare class FacebookApiException’ is closed to new replies.