Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#20851 closed feature request (duplicate)

Expand the capabilities of oembed

Reported by: Otto42 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.2
Component: Embeds Keywords:
Focuses: Cc:


WordPress's oembed support follows the spec quite nicely, but doesn't really allow for expandability.

In particular, the fetch() function in WP_oEmbed only realistically allows for maxwidth and maxheight parameters. Adding onto these parameters isn't easily possible.

Modifying the fetch function to support arbitrary parameters from the embed shortcode to be passed on to the provider, as per provider support, is relatively easy, but can't be done with a plugin due to the lack of filters.

Example: https://dev.twitter.com/docs/api/1/get/statuses/oembed

Simple patch attached to support arbitrary filters.

Example of an embed code after the patch, using the align parameter to pass align=center to twitter's oembed call:

[embed align=center]https://twitter.com/Otto42/status/210198339386482688[/embed]

Related: #19626

Attachments (1)

20851.diff (998 bytes) - added by Otto42 3 years ago.
Allow arbitrary params to be passed to oembed providers

Download all attachments as: .zip

Change History (9)

3 years ago

Allow arbitrary params to be passed to oembed providers

#1 @ipstenu
3 years ago

  • Cc ipstenu added

#2 @sabreuse
3 years ago

  • Cc sabreuse@… added

#3 @nacin
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

This quickly becomes a security issue: #16996

#4 @Otto42
3 years ago

Okay, so, if security is a problem, then at least make it pluggable somehow so that I can write a plugin to let me do this.

As it stands now, I have to hack core to do this. Not fun to keep having to maintain that.

#5 @nacin
3 years ago

As it stands now, I have to hack core to do this. Not fun to keep having to maintain that.

Not true — while it is non-obvious, you can hook into pre_http_request, when an HTTP request is triggered by WP_oEmbed->_fetch_with_format(). You can also filter it using the oembed_result filter and re-issue a fetch() with your own URL. Or you can do a global filter for wp_embed_defaults().

I proposed the possibility of more obvious/discrete filters in #16996.

#6 @Otto42
3 years ago

pre_http_request and filtering wp_embed_defaults don't give you the args from the shortcode, so you can only affect things on a global scale.

Reissuing the fetch is just bad mojo, obviously. Go to all the effort of making an HTTP request only to throw it away and do it all over again differently? Please.

I'll add a patch for #16996 to add a filter. It's a simple one-liner to make this pluggable. Just filter the $provider string and pass the $args and $url along as well.

#7 @DrewAPicture
3 years ago

  • Cc xoodrew@… added

#8 @DrewAPicture
3 years ago

  • Cc xoodrew@… removed
Note: See TracTickets for help on using tickets.