diff --git src/wp-admin/js/widgets/media-video-widget.js src/wp-admin/js/widgets/media-video-widget.js
index 9eb532caa6..eaddcbc348 100644
|
|
|
134 | 134 | }, |
135 | 135 | |
136 | 136 | /** |
137 | | * Whether a url is a supported external host. |
| 137 | * Whether MediaElement.js can directly play the URL from an external providers. |
138 | 138 | * |
139 | 139 | * @param {String} url - Video url. |
140 | 140 | * @returns {boolean} Whether url is a supported video host. |
… |
… |
|
151 | 151 | * @returns {void} |
152 | 152 | */ |
153 | 153 | renderPreview: function renderPreview() { |
154 | | var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl, poster, isHostedEmbed = false, mime, error; |
| 154 | var control = this, previewContainer, previewTemplate, attachmentId, attachmentUrl, poster, canHostedVideoPlayByMEJS = false, isOEmbed = false, mime, error, urlParser, matches; |
155 | 155 | attachmentId = control.model.get( 'attachment_id' ); |
156 | 156 | attachmentUrl = control.model.get( 'url' ); |
157 | 157 | error = control.model.get( 'error' ); |
… |
… |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | if ( ! attachmentId && attachmentUrl ) { |
164 | | isHostedEmbed = control.isHostedVideo( attachmentUrl ); |
165 | | } |
166 | | |
167 | | if ( isHostedEmbed ) { |
168 | | control.fetchEmbed(); |
169 | | poster = control.oembedResponses[ attachmentUrl ] ? control.oembedResponses[ attachmentUrl ].thumbnail_url : null; |
| 164 | canHostedVideoPlayByMEJS = control.isHostedVideo( attachmentUrl ); |
170 | 165 | } |
171 | 166 | |
172 | 167 | // Verify the selected attachment mime is supported. |
… |
… |
|
175 | 170 | if ( ! _.contains( _.values( wp.media.view.settings.embedMimes ), mime ) ) { |
176 | 171 | error = 'unsupported_file_type'; |
177 | 172 | } |
| 173 | } else if ( ! attachmentId ) { |
| 174 | urlParser = document.createElement( 'a' ); |
| 175 | urlParser.href = attachmentUrl; |
| 176 | matches = urlParser.pathname.toLowerCase().match( /\.(\w+)$/ ); |
| 177 | if ( matches ) { |
| 178 | if ( ! _.contains( _.keys( wp.media.view.settings.embedMimes ), matches[1] ) ) { |
| 179 | error = 'unsupported_file_type'; |
| 180 | } |
| 181 | } else { |
| 182 | isOEmbed = true; // @todo Parse the path from the attachmentUrl and grab the extension to see if it is a supported MIME. |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | if ( isOEmbed ) { |
| 187 | control.fetchEmbed(); |
| 188 | poster = control.oembedResponses[ attachmentUrl ] ? control.oembedResponses[ attachmentUrl ].thumbnail_url : null; |
178 | 189 | } |
179 | 190 | |
180 | 191 | previewContainer = control.$el.find( '.media-widget-preview' ); |
… |
… |
|
182 | 193 | |
183 | 194 | previewContainer.html( previewTemplate({ |
184 | 195 | model: { |
185 | | attachment_id: control.model.get( 'attachment_id' ), |
| 196 | attachment_id: attachmentId, |
186 | 197 | src: attachmentUrl, |
187 | 198 | poster: poster |
188 | 199 | }, |
189 | | is_hosted_embed: isHostedEmbed, |
| 200 | is_hosted_embed: canHostedVideoPlayByMEJS, |
| 201 | is_oembed: isOEmbed |
190 | 202 | error: error |
191 | 203 | })); |
192 | 204 | wp.mediaelement.initialize(); |
diff --git src/wp-admin/js/widgets/media-widgets.js src/wp-admin/js/widgets/media-widgets.js
index 5e7383c6fc..ad21e37a7e 100644
|
|
wp.mediaWidgets = ( function( $ ) { |
184 | 184 | return; |
185 | 185 | } |
186 | 186 | |
187 | | // If video, test for Vimeo and YouTube, otherwise, renderFail(). This should be removed once #34115 is resolved. |
188 | | if ( 'video' === this.controller.options.mimeType && ! /vimeo|youtu\.?be/.test( urlParser.host ) ) { |
189 | | embedLinkView.renderFail(); |
190 | | return; |
191 | | } |
192 | | |
193 | 187 | // Support YouTube embed links. |
194 | 188 | url = embedLinkView.model.get( 'url' ); |
195 | 189 | re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/; |
diff --git src/wp-includes/widgets/class-wp-widget-media-video.php src/wp-includes/widgets/class-wp-widget-media-video.php
index 5ba0526961..f56c475def 100644
|
|
class WP_Widget_Media_Video extends WP_Widget_Media { |
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | | add_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); |
| 124 | $yt_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#'; |
| 125 | $vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#'; |
| 126 | if ( ! $attachment && ! preg_match( $yt_pattern, $src ) && ! preg_match( $vimeo_pattern, $src ) ) { |
125 | 127 | |
126 | | echo wp_video_shortcode( |
127 | | array_merge( |
128 | | $instance, |
129 | | compact( 'src' ) |
130 | | ), |
131 | | $instance['content'] |
132 | | ); |
| 128 | // @todo inject_video_max_width_style? |
| 129 | echo wp_oembed_get( $src ); |
| 130 | |
| 131 | } else { |
| 132 | add_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); |
| 133 | |
| 134 | echo wp_video_shortcode( |
| 135 | array_merge( |
| 136 | $instance, |
| 137 | compact( 'src' ) |
| 138 | ), |
| 139 | $instance['content'] |
| 140 | ); |
133 | 141 | |
134 | | remove_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); |
| 142 | remove_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) ); |
| 143 | } |
135 | 144 | } |
136 | 145 | |
137 | 146 | /** |
… |
… |
class WP_Widget_Media_Video extends WP_Widget_Media { |
227 | 236 | <div class="notice notice-error notice-alt"> |
228 | 237 | <p><?php _e( 'Unable to preview media due to an unknown error.' ); ?></p> |
229 | 238 | </div> |
230 | | <# } else if ( data.is_hosted_embed && data.model.poster ) { #> |
| 239 | <# } else if ( data.model.poster ) { #> |
231 | 240 | <a href="{{ data.model.src }}" target="_blank" class="media-widget-video-link"> |
232 | 241 | <img src="{{ data.model.poster }}" /> |
233 | 242 | </a> |
234 | | <# } else if ( data.is_hosted_embed ) { #> |
235 | | <a href="{{ data.model.src }}" target="_blank" class="media-widget-video-link no-poster"> |
236 | | <span class="dashicons dashicons-format-video"></span> |
237 | | </a> |
| 243 | <# } else if ( data.model.is_oembed ) { #> |
| 244 | TODO: Safely embed the oEmbed in an iframe? Warning that moving the widget around in the sidebar would cause the iframe to be destroyed. |
238 | 245 | <# } else if ( data.model.src ) { #> |
239 | 246 | <?php wp_underscore_video_template() ?> |
240 | 247 | <# } #> |