WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 14 months ago

#23431 new feature request

[embed] shortcode doesn't work with do_shortcode()

Reported by: jtsternberg Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.5
Component: Embeds Keywords: has-patch
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 (1)

23431.diff (594 bytes) - added by jtsternberg 14 months ago.
Simple check for the [embed] shortcode that allows filtering via do_shortcode()

Download all attachments as: .zip

Change History (8)

comment:1 helen14 months ago

FWIW, you can do it through WP_Embed::run_shortcode().

comment:2 jtsternberg14 months 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)

Last edited 14 months ago by jtsternberg (previous) (diff)

comment:3 jtsternberg14 months 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?

Last edited 14 months ago by jtsternberg (previous) (diff)

comment:4 jtsternberg14 months 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.

comment:5 helen14 months 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.

jtsternberg14 months ago

Simple check for the [embed] shortcode that allows filtering via do_shortcode()

comment:6 SergeyBiryukov14 months ago

  • Component changed from General to Embeds
  • Version changed from trunk to 3.5

comment:7 jtsternberg14 months ago

  • Keywords has-patch added; needs-patch removed
Note: See TracTickets for help on using tickets.