[wp-trac] [WordPress Trac] #23431: [embed] shortcode doesn't work with do_shortcode()

WordPress Trac noreply at wordpress.org
Tue Jun 3 11:31:57 UTC 2014

#23431: [embed] shortcode doesn't work with do_shortcode()
 Reporter:  jtsternberg      |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  4.0
Component:  Embeds           |     Version:  3.5
 Severity:  normal           |  Resolution:
 Keywords:  has-patch        |     Focuses:

Comment (by kovshenin):

 I think we need to be careful here.

 As you probably know, `[embed]` is a bit special, and it runs earlier than
 any other shortcode. The embed shortcode can actually return another
 shortcode as of 3.6, see `wp_embed_handler_audio()` in media.php which
 works fine with posts and the_content, but you'd need to run the result
 twice through `do_shortcode()` if you're going to do it manually.

 There's also a caching mechanism for oEmbed which uses post meta to store
 the data. It uses the current post global, which means that if you're
 running the embed shortcode (or the_content filter for that matter)
 manually without an explicit post context (outside of the loop), you can
 get pretty weird stuff, like non-relevant oembed cache data stored with
 the last post of the main query, meaning a "cache flush" every time you
 publish a new post.

 That said using the `run_shortcode()` method is overkill in this scenario,
 because you already know the shortcode tag and the URL you'd like to
 embed, so there's no reason to run the regex in `do_shortcode()` one more
 time. You can invoke the `shortcode()` method directly, which will happily
 accept shortcode attributes in standard form, and doing that is
 essentially the same as registering an actual (vs fake) callback for the
 embed shortcode, see [attachment:23431.2.diff].

Ticket URL: <https://core.trac.wordpress.org/ticket/23431#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list