diff --git src/wp-admin/js/widgets/media-video-widget.js src/wp-admin/js/widgets/media-video-widget.js
index 547c4efc48..d74145eee1 100644
|
|
|
|
| 98 | 98 | */ |
| 99 | 99 | fetchEmbed: function fetchEmbed() { |
| 100 | 100 | var control = this, url; |
| 101 | | url = control.model.get( 'url' ); |
| | 101 | url = jQuery.trim( control.model.get( 'url' ) ); |
| 102 | 102 | |
| 103 | 103 | // If we already have a local cache of the embed response, return. |
| 104 | 104 | if ( control.oembedResponses[ url ] ) { |
| … |
… |
|
| 113 | 113 | control.fetchEmbedDfd = jQuery.ajax({ |
| 114 | 114 | url: wp.media.view.settings.oEmbedProxyUrl, |
| 115 | 115 | data: { |
| 116 | | url: control.model.get( 'url' ), |
| | 116 | url: url, |
| 117 | 117 | maxwidth: control.model.get( 'width' ), |
| 118 | 118 | maxheight: control.model.get( 'height' ), |
| 119 | 119 | _wpnonce: wp.media.view.settings.nonce.wpRestApi, |
| … |
… |
|
| 142 | 142 | renderPreview: function renderPreview() { |
| 143 | 143 | var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl, poster, isHostedEmbed = false, parsedUrl, mime, error; |
| 144 | 144 | attachmentId = control.model.get( 'attachment_id' ); |
| 145 | | attachmentUrl = control.model.get( 'url' ); |
| | 145 | attachmentUrl = jQuery.trim( control.model.get( 'url' ) ); |
| 146 | 146 | error = control.model.get( 'error' ); |
| 147 | 147 | |
| 148 | 148 | if ( ! attachmentId && ! attachmentUrl ) { |
diff --git src/wp-admin/js/widgets/media-widgets.js src/wp-admin/js/widgets/media-widgets.js
index cd03b09633..7dd10f154a 100644
|
|
|
wp.mediaWidgets = ( function( $ ) { |
| 142 | 142 | /** |
| 143 | 143 | * Fetch media. |
| 144 | 144 | * |
| 145 | | * This is a TEMPORARY measure until the WP API supports an oEmbed proxy endpoint. See #40450. |
| 146 | | * |
| 147 | | * @see https://core.trac.wordpress.org/ticket/40450 |
| 148 | 145 | * @returns {void} |
| 149 | 146 | */ |
| 150 | 147 | fetch: function() { |
| 151 | | var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser; // eslint-disable-line consistent-this |
| | 148 | var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser, url; // eslint-disable-line consistent-this |
| | 149 | url = $.trim( embedLinkView.model.get( 'url' ) ); |
| 152 | 150 | |
| 153 | 151 | if ( embedLinkView.dfd && 'pending' === embedLinkView.dfd.state() ) { |
| 154 | 152 | embedLinkView.dfd.abort(); |
| … |
… |
wp.mediaWidgets = ( function( $ ) { |
| 167 | 165 | }; |
| 168 | 166 | |
| 169 | 167 | urlParser = document.createElement( 'a' ); |
| 170 | | urlParser.href = embedLinkView.model.get( 'url' ); |
| | 168 | urlParser.href = url; |
| 171 | 169 | matches = urlParser.pathname.toLowerCase().match( /\.(\w+)$/ ); |
| 172 | 170 | if ( matches ) { |
| 173 | 171 | fileExt = matches[1]; |
| … |
… |
wp.mediaWidgets = ( function( $ ) { |
| 184 | 182 | embedLinkView.dfd = $.ajax({ |
| 185 | 183 | url: wp.media.view.settings.oEmbedProxyUrl, |
| 186 | 184 | data: { |
| 187 | | url: embedLinkView.model.get( 'url' ), |
| | 185 | url: url, |
| 188 | 186 | maxwidth: embedLinkView.model.get( 'width' ), |
| 189 | 187 | maxheight: embedLinkView.model.get( 'height' ), |
| 190 | 188 | _wpnonce: wp.media.view.settings.nonce.wpRestApi, |
| … |
… |
wp.mediaWidgets = ( function( $ ) { |
| 779 | 777 | mediaFramePropToModelPropMap[ fieldSchema.media_prop || modelProp ] = modelProp; |
| 780 | 778 | }); |
| 781 | 779 | |
| | 780 | // Trim whitespace from url since it causes problems with oembeds. |
| | 781 | if ( mediaFrameProps.url ) { |
| | 782 | mediaFrameProps.url = $.trim( mediaFrameProps.url ); |
| | 783 | } |
| | 784 | |
| 782 | 785 | _.each( mediaFrameProps, function( value, mediaProp ) { |
| 783 | 786 | var propName = mediaFramePropToModelPropMap[ mediaProp ] || mediaProp; |
| 784 | 787 | if ( control.model.schema[ propName ] ) { |
diff --git src/wp-includes/media.php src/wp-includes/media.php
index 6843c61b21..be6c328167 100644
|
|
|
function wp_enqueue_media( $args = array() ) { |
| 3424 | 3424 | 'audio' => ( $show_audio_playlist ) ? 1 : 0, |
| 3425 | 3425 | 'video' => ( $show_video_playlist ) ? 1 : 0, |
| 3426 | 3426 | ), |
| 3427 | | 'oEmbedProxyUrl' => rest_url( 'oembed/1.0/proxy' ), |
| | 3427 | 'oEmbedProxyUrl' => preg_replace( '#^\w+:#', '', rest_url( 'oembed/1.0/proxy' ) ), |
| 3428 | 3428 | 'embedExts' => $exts, |
| 3429 | 3429 | 'embedMimes' => $ext_mimes, |
| 3430 | 3430 | 'contentWidth' => $content_width, |
diff --git tests/qunit/wp-admin/js/widgets/test-media-video-widget.js tests/qunit/wp-admin/js/widgets/test-media-video-widget.js
index f3b111ecc5..69d9ff6197 100644
|
|
|
|
| 28 | 28 | equal( mappedProps.preload, 'meta', 'mapModelToMediaFrameProps should set preload' ); |
| 29 | 29 | |
| 30 | 30 | // Test mapMediaToModelProps(). |
| 31 | | mappedProps = videoWidgetControlInstance.mapMediaToModelProps( { loop: false, preload: 'meta', url: testVideoUrl, title: 'random movie file title' } ); |
| | 31 | mappedProps = videoWidgetControlInstance.mapMediaToModelProps( { loop: false, preload: 'meta', url: testVideoUrl + ' ', title: 'random movie file title' } ); |
| 32 | 32 | equal( mappedProps.title, undefined, 'mapMediaToModelProps should ignore title inputs' ); |
| 33 | 33 | equal( mappedProps.loop, false, 'mapMediaToModelProps should set loop' ); |
| 34 | 34 | equal( mappedProps.preload, 'meta', 'mapMediaToModelProps should set preload' ); |
| | 35 | equal( mappedProps.url, testVideoUrl, 'mapMediaToModelProps should trim whitespace from urls' ); |
| 35 | 36 | }); |
| 36 | 37 | |
| 37 | 38 | test( 'video widget control renderPreview', function( assert ) { |