WordPress.org

Ready to get started?Download WordPress

Forums

WPBook
[resolved] Cannot redeclare class FacebookApiException (14 posts)

  1. Olivier
    Member
    Posted 3 years ago #

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

  2. johneckman
    Member
    Plugin Author

    Posted 3 years ago #

    @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?

  3. johneckman
    Member
    Plugin Author

    Posted 3 years ago #

    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.

  4. Olivier
    Member
    Posted 3 years ago #

    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...

  5. Olivier
    Member
    Posted 3 years ago #

    I've disabled "Comments for Facebook" and will try to send the article to Facebook to see if it helps.

  6. johneckman
    Member
    Plugin Author

    Posted 3 years ago #

    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?

  7. johneckman
    Member
    Plugin Author

    Posted 3 years ago #

    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?

  8. johneckman
    Member
    Plugin Author

    Posted 3 years ago #

    D'oh, figured it out.

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

    to
    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.

  9. Olivier
    Member
    Posted 3 years ago #

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

    Thanks for fixing this :)

  10. Jon Yoder
    Member
    Posted 3 years ago #

    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.

  11. Brooke Dukes
    Member
    Plugin Contributor

    Posted 3 years ago #

    @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.

  12. Steve
    Member
    Posted 3 years ago #

    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.

  13. Brooke Dukes
    Member
    Plugin Contributor

    Posted 3 years ago #

    @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 :)

  14. Steve
    Member
    Posted 3 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic