WordPress.org

Ready to get started?Download WordPress

Forums

Jetpack by WordPress.com
[resolved] Jetpack processes shortcodes twice? (33 posts)

  1. zingiri
    Member
    Posted 1 year ago #

    It seems that after activating Jetpack, WP shortcodes are processed twice. Once as part of the wp_head() execution (unexpected) and once in the loop (as expected).
    I suspect this is because of an additional do_shortcode() call in one of the Jetpack actions.
    Can this be resolved or is there a way to avoid shortcodes to be triggered inside the header?

    http://wordpress.org/extend/plugins/jetpack/

  2. Tim Moore
    Moderator
    Plugin Author

    Posted 1 year ago #

    Can you provide an example of where this is happening?

    Also, is there a specific plugin that this happens with?

  3. zingiri
    Member
    Posted 1 year ago #

    It's been happening with one of our plugins, the Bookings plugin and reported by a couple of our users.
    It can be replicated with the following code:

    add_shortcode( 'bookings', 'bookings_shortcode' );
    function bookings_shortcode( $atts, $content=null, $code="" ) {
    return 'test';
    }

    In this case 'test' will be output in the header and on the page.
    Note that the above is an abreviated version of the code used in the Bookings plugin.

  4. Tim Moore
    Moderator
    Plugin Author

    Posted 1 year ago #

    Thanks for the info; we are looking into this issue.

  5. Tim Moore
    Moderator
    Plugin Author

    Posted 1 year ago #

    I'm unable to reproduce this using Jetpack 2.1.1 and latest WordPress.

    Are you by chance using get_the_excerpt or get_the_content or the_excerpt or the_content actions in your plugin?

  6. zingiri
    Member
    Posted 1 year ago #

    No, not using any of those. Maybe it's caused by a combination of Jetpack with another plugin. The person who reported the issue managed to resolve it by disabling Jetpack.

  7. Tim Moore
    Moderator
    Plugin Author

    Posted 1 year ago #

    It's possible. If you want to have the person who reported the issue contact us directly, our email address is support@jetpack.me. We'd be happy to help resolve this and get whatever fix in place that is necessary. I just need some more debugging info to go in first :)

    Thanks!

  8. zingiri
    Member
    Posted 1 year ago #

    OK, thanks for your help so far. I will let the person know.

  9. David Anderson
    Member
    Posted 1 year ago #

    I have this problem too. I placed a PHP warning and got a stack trace. Here's how JetPack is calling the shortcode:

    PHP Stack trace:
    PHP 1. {main}() /mywebsite/index.php:0
    PHP 2. require() /mywebsite/index.php:17
    PHP 3. require_once() /mywebsite/wp-blog-header.php:16
    PHP 4. include() /mywebsite/wp-includes/template-loader.php:43
    PHP 5. get_header() /mywebsite/wp-content/themes/cloudhost-parent/page.php:4
    PHP 6. locate_template() /mywebsite/wp-includes/general-template.php:34
    PHP 7. load_template() /mywebsite/wp-includes/template.php:366
    PHP 8. require_once() /mywebsite/wp-includes/template.php:390
    PHP 9. wp_head() /mywebsite/wp-content/themes/cloudhost-child/header.php:33
    PHP 10. do_action() /mywebsite/wp-includes/general-template.php:1576
    PHP 11. call_user_func_array() /mywebsite/wp-includes/plugin.php:403
    PHP 12. jetpack_og_tags() /mywebsite/wp-includes/plugin.php:403
    PHP 13. jetpack_og_get_image() /mywebsite/wp-content/plugins/jetpack/functions.opengraph.php:71
    PHP 14. Jetpack_PostImages::get_images() /mywebsite/wp-content/plugins/jetpack/functions.opengraph.php:109
    PHP 15. Jetpack_PostImages::from_html() /mywebsite/wp-content/plugins/jetpack/class.jetpack-post-images.php:407
    PHP 16. apply_filters() /mywebsite/wp-content/plugins/jetpack/class.jetpack-post-images.php:254
    PHP 17. call_user_func_array() /mywebsite/wp-includes/plugin.php:170
    PHP 18. do_shortcode() /mywebsite/wp-includes/plugin.php:170

    The shortcode then gets called a second time in the ordinary way:

    PHP Stack trace:
    PHP 1. {main}() /mywebsite/index.php:0
    PHP 2. require() /mywebsite/index.php:17
    PHP 3. require_once() /mywebsite/wp-blog-header.php:16
    PHP 4. include() /mywebsite/wp-includes/template-loader.php:43
    PHP 2. require() /mywebsite/index.php:17
    PHP 3. require_once() /mywebsite/wp-blog-header.php:16
    PHP 4. include() /mywebsite/wp-includes/template-loader.php:43
    PHP 5. the_content() /mywebsite/wp-content/themes/cloudhost-parent/page.php:26
    PHP 6. apply_filters() /mywebsite/wp-includes/post-template.php:166
    PHP 6. apply_filters() /mywebsite/wp-includes/post-template.php:166
    PHP 7. call_user_func_array() /mywebsite/wp-includes/plugin.php:170
    PHP 8. do_shortcode() /mywebsite/wp-includes/plugin.php:170

    This caused me a big problem, as the shortcode was processing _POST parameters - twice.

  10. David Anderson
    Member
    Posted 1 year ago #

    P.S. Disabling Photonic only (not the rest of JetPack) removed the double-call.

  11. David Anderson
    Member
    Posted 1 year ago #

    I spoke too soon - the error has returned, even whilst Photonic is off.

  12. zingiri
    Member
    Posted 1 year ago #

    Thanks David, hopefully this gives Tim more info in order to resolve the issue.

  13. Manoj Chacko
    Member
    Posted 1 year ago #

    Is there any updates on this. I have this problem on my live site. Is their a temporary work around, other than disabling it?

  14. Tim Moore
    Moderator
    Plugin Author

    Posted 1 year ago #

    I'll take a look at this and get a fix out as soon as I can.

  15. bobbyl76
    Member
    Posted 1 year ago #

    This is also happening to a theme forest theme I'm using called Natural. The galleria shortcode is broken by this same issue. I hope you guys find a workaround quickly. I want to use both Jetpack and galleria.

    http://www.bobbylopezcreative.com/port/

  16. smartypants
    Member
    Posted 1 year ago #

    Confirmed this happening with my plugin sp client document manager plugin as well. It seems to be running the shortcode once before the document and once again in the document.

  17. smartypants
    Member
    Posted 1 year ago #

    Actually sorry, just updated to jetpack 2.1.1 and all seems clear. Not running shortcodes twice anymore. Thanks for the fix!

  18. bobbyl76
    Member
    Posted 1 year ago #

    I really hope you guys find some kind of work around. :(

  19. smartypants
    Member
    Posted 1 year ago #

    hey bobby this should be fixed in 2.1.1, it's fixed here.

  20. David Anderson
    Member
    Posted 1 year ago #

    Perhaps you had a different bug; the stack-trace I produced above showing the double-call was on 2.1.1.

  21. bobbyl76
    Member
    Posted 1 year ago #

    not so for me smartypants. http://www.bobbylopezcreative.com/port/ I'm getting the error with my galleria shortcode. the newest jetpack update didn't fix my problem. See the error on the slider "Init failed: Galleria could not find the element "#galleria-1"."

  22. Manoj Chacko
    Member
    Posted 1 year ago #

    I started getting the error on 2.1.1

  23. Manoj Chacko
    Member
    Posted 1 year ago #

    I did not have that error initially when I upgraded it 2 weeks back the error happened 4-5 days ago, some thing got changed at that point

  24. mulli.bahr
    Member
    Posted 1 year ago #

    I have the same problem of [shortcode]text[/shortcode]
    called twice.
    WP 3.5, no jetpack, just plain shortcode as in Codex:

    function bibl_func($atts, $content = null) {
       extract(shortcode_atts(array(
          'title' => 'some title',
          'clickme'  => 'click me'
       ), $atts));
    //       if (is_null($content)) return ""; // did not help
           return '<div class="clickme" style="cursor:pointer;"> click me! </div><div class="bibl">'. $content .'</div>' ;
    }
    add_shortcode('bibl', 'bibl_func');

    Any idea how to solve it?

  25. Manoj Chacko
    Member
    Posted 1 year ago #

    Hi Tim,

    Any updates on this,

  26. Tim Moore
    Moderator
    Plugin Author

    Posted 1 year ago #

    This isn't a Jetpack bug: http://lists.automattic.com/pipermail/wp-hackers/2013-January/045053.html

    To summarize the link: Jetpack uses the get_the_excerpt function properly. Other plugins/themes are not, which is causing the post content for these posts to get generated twice, thus processing the shortcodes twice.

    Despite that, we're going to look at changing the Jetpack code from the current, proper way of doing this to another way to alleviate some of these issues for Jetpack users.

    Be aware, though, that while this will solve an incompatibility with Jetpack, if you run another plugin that, like Jetpack, is doing_it_right, you'll see these same issues crop up again.

  27. Manoj Chacko
    Member
    Posted 1 year ago #

    What is the other solution, most of the shortcodes I have is custom plugin, which are all basic plugins, and using the shortcode API

  28. Manoj Chacko
    Member
    Posted 1 year ago #

    This still not fixed on the new version

  29. Tim Moore
    Moderator
    Plugin Author

    Posted 1 year ago #

    @Manoj: we've put a fix in place in Jetpack 2.1.2. If you can share what plugin or code you are having an issue with, we can try to help.

  30. Manoj Chacko
    Member
    Posted 1 year ago #

    This is a test function

    <?php
    function foobar_func( $atts ){
    echo "Shortcode Test Successfull";
    }
    add_shortcode( 'foobar', 'foobar_func' );
    ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.