WordPress.org

Ready to get started?Download WordPress

Forums

Facebook Like Thumbnail
Why is do_shortcode call as part of the wp_head action? (9 posts)

  1. Mike Walsh
    Member
    Posted 1 year ago #

    I am trying to understand why do_shortcode is being called as part of the wp_action? It is causing other shortcodes to be processed as part of wp_head and they then get processed again as part of the page content. In some cases this results in bad data if the shortcode actually does some processing.

    http://wordpress.org/extend/plugins/facebook-like-thumbnail/

  2. Ashfame
    Member
    Plugin Author

    Posted 1 year ago #

    Can you give examples of possible issues?

    You are right shortcodes are processed again on the post page, but they both or infact any no of do_shortcode() calls are isolated. The only area where this could cause an issue with some other plugin will be when that plugin is using filter in place of where it should be using action.

  3. Mike Walsh
    Member
    Posted 1 year ago #

    I have a Google Forms plugin which allows users to embed Google Forms within a post or a page using a short code. When the short code is called twice on the same page (which is happening as a result of your plugin), it causes the form to be posted incorrectly (it hasn't been filled out yet because it hasn't been rendered).

    I am not sure I understand your statement above about do_shortcode() being isolated. From what I observed it appears that any shortcode which appeared on a post was being processed in both the wp_head processing as well as the page processing.

  4. Ashfame
    Member
    Plugin Author

    Posted 1 year ago #

    Can you share the code so that I can take a look?

  5. Mike Walsh
    Member
    Posted 1 year ago #

    Sure - download the plugin here. Create a sample form using Google Forms. If you don't want to set up a Google Form , drop me an email (same as my WordPress.org username @gmail.com) and I can send you a short code that you can use for testing.

  6. Ashfame
    Member
    Plugin Author

    Posted 1 year ago #

    Emailed you!

  7. Ashfame
    Member
    Plugin Author

    Posted 1 year ago #

    Looks like it doesn't work on a local setup. Anyways, here is what I have to say:

    I process the shortcodes so as to take in account of actual markup that is there after plugins like Nextgen have rendered their galleries. I am sure there will be cases where this needs to be done.

    Shortcode is by no means to be processed only once per page load. Its just like retrieving content with some on-the-fly modifications because we don't want them to be permanent.

    I understand you are trying to process form submission inside a shortcode but I see two ways of doing it, which are:

    1) Don't use the same url for submission, may be use a different endpoint. This way you only process the submission when you are on that particular URL. (Another instance - http://wordpress.stackexchange.com/questions/3902/best-practices-for-creating-and-handling-forms-with-plugins)

    2) Set a flag to process it only once. Like add a VERY UNIQUE key to the global $wpdb object indicating the form has been submitted, and only process it if that key in $wpdb object doesn't exist yet.

    Hope that helps! And very interesting question, though I am surprised I never ran into such a thing. Happy coding :)

    P.S. - I have asked the Question on WPSE for more developers feedback on approach #2 - http://wordpress.stackexchange.com/questions/57548/handling-form-submissions-in-shortcodes

  8. useStrict
    Member
    Posted 1 year ago #

    Hi Ashfame, the plugin is great, but the do_shortcode() is annoying - it broke eShop - the Proceed to Paypal button disappeared because it is added with an include_once() call; it was included in the first pass and then left out on the second and last pass of do_shortcode(). Another bad side effect is that any orders I get are processed twice.

    Please change your code so that it does not call do_shortcode().

    Thanks,
    Vinny

  9. Ashfame
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    You should have known from the discussion above that if a plugin assumes the shortcode will be processed only once per page load, then that's something they need to act on.

    I even have 2 possible ways of doing it in one of the post above. Have a look.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic