WordPress.org

Ready to get started?Download WordPress

Forums

Simple Facebook Connect
Open Graph tag generation method causing plugin conflicts (6 posts)

  1. Graham Stoney
    Member
    Posted 2 years ago #

    Hey Otto,

    Firstly, thanks for an awesome plugin!

    I've noticed that the method Simple Facebook Connect uses to generate Open Graph tags causes the post or page being displayed to be processed twice: once to extract the tags, and once to show to the user. This can cause conflicts with other plugins which trigger actions (such as sending an email or performing some other transaction) when their content filters or shortcodes are run. Most content filters work fine when called twice, but in some cases this causes breakage.

    Would it be possible to generate Open Graph tags after WordPress has run its normal content filters, say by registering a content filter of your own with a high priority?

    I like SFC, but the way content filters get called twice has caused me grief in the past, and it always surprises me when I get tripped up by this.

    Thanks,
    Graham

    http://wordpress.org/extend/plugins/simple-facebook-connect/

  2. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 2 years ago #

    In short, no, that method won't work. By the time the normal content filters run, it's too late to add stuff to the head of the page. OpenGraph content must be in the head of the page for FB to see it, and content filters normally only run when producing the content lower down in the page.

    The long version of my response to this you can find here: http://ottopress.com/2011/actions-and-filters-are-not-the-same-thing/

    Summary: Other plugins should not use filters (or shortcodes) to take actions like sending email or performing other non-repeatable transactions. Any plugin that is doing such a thing is doing-it-wrong and needs to be fixed.

    This is not an uncommon problem though, I've had to point out issues in plugins like this even to core developers when their plugins did it. It's a relatively easy mistake to make. The easy fix is usually to pull whatever code is performing the action in question out of the filter function, and to put it in a function being called by the proper action hook (usually "init") instead.

  3. Graham Stoney
    Member
    Posted 2 years ago #

    Hey Otto,

    Thanks for the quick reply. I can see what you're saying, but it also seems inefficient to generate the content and run all the filters twice. Seems like a chick-and-egg problem. I was surprised when I first dove into the SFC code and saw all the content processing it was duplicating.

    Would it be possible to add an option to en/disable Open Graph tag generation to work around problems like this? The only feature I use in SFC is Publish and I have little control over other plugin authors. :-(

    Thanks,
    Graham

  4. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 2 years ago #

    The "inefficiency" is minor, at best. Most all filters and shortcodes do nothing more than simple string processing. The benefits and ease-of-use outweigh the downside.

    And while you have little control over plugin authors, you do have the ability to tell them that their plugins are broken, and the ability to not use broken plugins. I suggest exercising that ability.

    BTW, SFC-Publish needs the meta to be there too. The manual publish triggers FB to crawl your site for it.

    I will not add an option to disable the meta generation, since most people don't need it. Options are counterproductive when the vast majority of people don't need to use them. "Decisions, not options."

    If you want to disable it yourself (breaking a lot of functionality in the process), then you can add a remove_action call somewhere to remove the sfc_base_meta function from the wp_head hook.

  5. Graham Stoney
    Member
    Posted 2 years ago #

    I understand your reasoning; I don't like having zillions of options either. I just want things to work. But sometimes it helps users to be able to disable certain functionality when there is a plugin conflict or duplicated functionality. I have two other plugins installed that also generate OpenGraph tags.

    Thanks for the tip. I'm not a fan of plugin-hacking, since the hack gets deleted in the next upgrade. I may have to resort to that; I've been playing with FacePress II for my wall updates, but it's just not as clean as SFC Publish. :(

    Cheers,
    Graham

  6. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 2 years ago #

    I have two other plugins installed that also generate OpenGraph tags.

    Betcha mine does it better. :)

    Just added audio support into 1.2. Video handling improvements are next, although I may have to write a whole frickin' library to make that one work.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic