Opened 12 years ago
Last modified 2 years ago
#23431 new feature request
[embed] shortcode doesn't work with do_shortcode()
Reported by: | jtsternberg | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 3.5 |
Component: | Embeds | Keywords: | has-patch needs-testing needs-unit-tests |
Focuses: | Cc: |
Description
It would be preferable to use the [embed] shortcode through do_shortcode rather than apply_filters( 'the_content',... in order to avoid sharing plugins, related posts plugins etc appending content to something that could simple be post meta, i.e. looking to convert a youtube url to a video.
Attachments (3)
Change History (16)
#2
@
12 years ago
No, that method doesn't work because it's not a proper static method and uses the $this
variable which is unavailable. I CAN do
$embed = new WP_Embed(); $video = $embed->run_shortcode( '[embed width="890"]'. esc_url( $video_url ) .'[/embed]' );
But that definitely seems like overkill to me. (Please correct me if I'm wrong)
#3
@
12 years ago
Ok, digging a bit further, I realized the WP_Embed
class is initialized as a global variable so is accessible to me via
$GLOBALS['wp_embed']->run_shortcode( '[embed width="890"]'. esc_url( $video_url ) .'[/embed]' );
So pardon my interruption here. :)
Curious, should we document that in the codex?
#4
@
12 years ago
Ok, another thought regarding the point of this ticket originally: it seems plausible that we could still enable this featured through do_shortcode()
by checking for the [embed] shortcode, and then running this method. I'll throw up a patch if I get a chance.
#5
@
12 years ago
Well, yes, working code would be global $wp_embed; $wp_embed->run_shortcode( $whatever );
. I'd check out the docs for the method - I think you'll find them helpful.
#9
@
11 years ago
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 23431.2.diff.
This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.
10 years ago
#13
@
2 years ago
- Milestone set to Future Release
23431.3.diff is a refresh that applies cleanly.
@swissspidy @azaozz As component maintainers, do you feel this is a change still worth making?
FWIW, you can do it through
WP_Embed::run_shortcode()
.