Make WordPress Core

Opened 18 months ago

Last modified 18 months ago

#44704 new defect (bug)

`wp.media.view.EmbedLink` and `oembed/1.0/proxy` don't work as expected

Reported by: 7studio Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.7
Component: Embeds Keywords:
Focuses: Cc:
PR Number:


It seems that wp.media.view.EmbedLink and the REST route oembed/1.0/proxy don't respect the maxwidth oEmbed parameter in all cases.

To Reproduce

Steps to reproduce the behaviour:

  1. Create a new post.
  2. Click on "Add Media" button.
  3. Choose "Insert from URL" interface.
  4. Paste a valid YouTube URL: https://www.youtube.com/watch?v=KA_CLal14u4
  5. See the YouTube <iframe> with a 600px width.
  6. Click on "Insert into post" button.
  7. Publish post.
  8. Edit the YouTube video.
  9. See the YouTube <iframe> with a tiny 200px width.

Expected behaviour

The embed contents from Facebook or other services should have the same width when you add or edit them.

Reason found

After some researches, it seems that the problem comes from media-view.js and this part of code:

this.dfd = wp.apiRequest({
        url: wp.media.view.settings.oEmbedProxyUrl,
        data: {
                url: url,
                maxwidth: this.model.get( 'width' ),
                maxheight: this.model.get( 'height' )
        type: 'GET',
        dataType: 'json',
        context: this

I don't know why the embed content this.model.get( 'width' ) is egal to 0 when we edit it :/ As a result, the default value for the maxwidth argument of the REST route oembed/1.0/proxy can't be used like the first time.

Here is the requested URL:

  1. when we try to embed YouTube video: http://v10.helloprojets.test/wp-json/oembed/1.0/proxy?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DscAxBpppwcQ%26list%3DPLoSIOFPSXQoOXzR8tpGC484wjgKFwIbWL%26index%3D78.
  2. when we edit the YouTube video: http://v10.helloprojets.test/wp-json/oembed/1.0/proxy?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DscAxBpppwcQ%26list%3DPLoSIOFPSXQoOXzR8tpGC484wjgKFwIbWL%26index%3D78&maxwidth=&maxheight=.

This problem is a bit weird and complex. I hope I was clear in my explanations ;)

Attachments (2)

insert-embed.png (109.2 KB) - added by 7studio 18 months ago.
edit-embed.png (25.3 KB) - added by 7studio 18 months ago.

Download all attachments as: .zip

Change History (4)

18 months ago

#1 @swissspidy
18 months ago

Sounds to me like oembed/1.0/proxy works as expected though. It's just the model data that isn't set correctly.

#2 @7studio
18 months ago

@swissspidy I preferred to talk about oembed/1.0/proxy too because the REST route could not accept zero/empty value for parameters and replace them by default values.

IMHO, it doesn't make sense to request content via oEmbed API with empty parameters (especially for YouTube and Dailymotion which return very small version of embeds without them). WordPress could handle/fix this developer mistake ;)

But you are right, the model data of wp.media.view.EmbedLink isn't correctly set and it's the main problem.

Note: See TracTickets for help on using tickets.