Link Library
conflict with Simple Facebook Connect (16 posts)

  1. axwax
    Posted 4 years ago #

    first of all thanks for such a great comprehensive plugin!

    I have run into an issue using Link Library together with Otto's Simple Facebook Connect http://wordpress.org/extend/plugins/simple-facebook-connect/

    As far as I can see SFC parses the_content() to add facebook metadata to the header of a post, which means the shortcodes get executed more than once on a page.

    I thought I managed to fix the issue by enclosing the offending shortcode function (link_library_addlink_func()) with an output buffer, as it currently echos validation messages, rather than return them.

    While this sorts out the multiple validation messages I still can't get it to play nicely with SFC, since the postdata gets processed 3 times.

    I'm not sure what the best course of action to fix this is (maybe post to a separate file rather the same form?). Do you have any ideas ?

    I guess the other option is to disable SFC on Link Library pages, as outlined here: http://wordpress.org/support/topic/plugin-simple-facebook-connect-questions-suggestions-re-newdev-version



  2. axwax
    Posted 4 years ago #

    Also, I just noticed that when the box next to "Allow link submission with empty link" is unticked, submitting with the Link URL field blank produces "New link submitted, it will appear in the list once moderated. Thank you.", but no link gets submitted. (This has nothing to do with SFC, it also happens with SFC disabled...)

    Shouldn't it return an error message instead?

  3. Shortcodes and filters should not have any side effects. In other words, yes, they can be called multiple times. They should be written so as to allow that to work properly, and they should not modify any globals or anything like that.

    Filters are supposed to *filter*. Not do other stuff.

  4. Yannick Lefebvre
    Plugin Author

    Posted 4 years ago #

    Hi Otto, We met briefly at the speakers dinner at Wordcamp Montreal this earlier this summer.

    I am not sure what you mean by writing shortcodes to work being called multiple times. By their nature, shortcodes will be called when a text string with square brackets is found in the page body and the shortcode function will return the text that is meant to replace that code. If the content is parsed multiple times for shortcodes, only the first time should result in the replacement of the shortcode by the intended content, right?

    Is there anything else you would recommend doing to work well in this instance? Perhaps an example to point me to?

  5. If the content is parsed multiple times for shortcodes, only the first time should result in the replacement of the shortcode by the intended content, right?

    No. The shortcode function should return the replacement content for the shortcode every time it is called. You cannot guarantee that the original unmodified content will only be parsed one time per page.

    What if I did this?

    $content_a = apply_filters('the_content',$post->post_content);
    $content_b = apply_filters('the_content',$post->post_content);

    Your shortcode function will be called twice, once to generate $content_a, a second time to generate $content_b. Now, obviously this is a contrived example, but the point is that you can't control how people call your shortcode or when it gets processed.

    Basically, filters (and by extension shortcodes) should not have side effects. They should not modify globals, ever. They should not do different things at different times. They should only process the content as a filter (or process the shortcode) and return the replacement text. That's what filters do. That's all filters *should* do.

  6. Yannick Lefebvre
    Plugin Author

    Posted 4 years ago #

    I will go through my code this week-end to correct the echo statements for the link submission and see if I might be doing anything else but returning the replacement text.

  7. Yannick Lefebvre
    Plugin Author

    Posted 4 years ago #

    I just released version 5.3 to hopefully address these issues. I made sure that all shortcode output was returned and added a new message when you submit a link without an address when such links are not accepted.

    That being said, the plugin is currently suspended because of a security issue which I had already corrected a week ago. For some reason, the person who contacted me about it last week still reported it on a security site even though I had fixed it, which resulted in a suspension of the plugin.

    Please try updating as soon as version 5.3 is available and let me know if it works better.

  8. Link library doesn't look suspended to me: http://wordpress.org/extend/plugins/link-library/

  9. axwax
    Posted 4 years ago #

    thanks for having a look at it!

    Unfortunately, while the new version has fixed the first issue (now there is only one validation message), submitting a link still generates 3 posts in the moderation queue (and sends out 3 emails).

    I'm not sure if that's easily solvable - I guess it means either the $_POST array needs to be cleared once it has been processed, or it needs to post to another php script to process the submission (via some AJAX voodoo?)...

    I just checked: this also happens when using an external 'submitted' page (with [link-library-addlinkcustommsg]).

    Sorry for being the bearer of bad news...

  10. Yannick Lefebvre
    Plugin Author

    Posted 4 years ago #

    Hi Axwax,

    Ah, now I understand better what is happening. While you had mentioned that the processing was happening three times, you had not said that the net effect was that you would end up with three copies of the link under your database waiting for moderation.

    This should be fixable since the plugin is supposed to check if links already exist in the database before inserting them. There must be something wrong with that logic. I will be only be able to look into that around next week-end. Hang tight.


  11. Yannick Lefebvre
    Plugin Author

    Posted 4 years ago #

    Otto, the plugin was re-opened Sunday around 5pm eastern.

  12. axwax
    Posted 4 years ago #

    Oops, sorry for being rather vague on my initial post.
    Btw, I'm happy to test any changes to the plugin before you commit it to W.org (I've just sent you a message through your contact form, so you should have my email)
    There's no rush on my part, as I've implemented the workaround mentioned above: http://wordpress.org/support/topic/plugin-simple-facebook-connect-questions-suggestions-re-newdev-version

  13. duffz00
    Posted 4 years ago #


    I have exactly the same problem with running your great link-library plugin and SFC. Every submitted link generates two post for moderation. Would be nice if you can find a fix ;)


  14. Yannick Lefebvre
    Plugin Author

    Posted 4 years ago #

    I just released version 5.3.3 to address this issue. There was first a problem with the code to check if a link was already in the system, thus the multiple submissions. Now, the main issue is that the code cannot know if the link was submitted twice because of such a double-shortcode processing or because someone submitted the same twice. Therefore, I created an option to choose if there should be an error message displayed or not when duplicate links are sent. When this option is unchecked, it will just display the moderation message and discard the duplicate.

    Let me know if this helps.

  15. jack: Perhaps you should move the code that does the processing of submitted links out of the shortcode handler entirely, and into something triggered on the init action or similar.

    Filters, and by extension shortcodes, should not have side effects of any kind. Modifying data in the database is a side-effect.

    Shortcodes should simply return something to be displayed, they shouldn't do anything of substance. As long as you have a filter/shortcode which takes any form of action, you'll continually run into these problems.

    Refactor. Move the "doing" code outside the shortcode handler functions.

  16. Yannick Lefebvre
    Plugin Author

    Posted 4 years ago #

    Thanks for your advice. I was actually thinking about that after issuing my update last night. I refactored this to send the form post data to an external php file to process, then using a wp_redirect with a URL variable to display a message on the page. So the shortcode no longer has any side-effect.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Link Library
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic