From b938bfb7d51c197bef11db22b0ddc9f4aa2d193c Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 7 Aug 2014 05:53:15 +0000 Subject: [PATCH] MediaElement upgrade: cleanup for generated markup for videos. See #29110. Built from https://develop.svn.wordpress.org/trunk@29429 git-svn-id: http://core.svn.wordpress.org/trunk@29207 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media-template.php | 34 +++++++++++++++++++++++++++------- wp-includes/media.php | 9 ++++++++- wp-includes/post-template.php | 3 +++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/wp-includes/media-template.php b/wp-includes/media-template.php index 24493a01b1..084228e27f 100644 --- a/wp-includes/media-template.php +++ b/wp-includes/media-template.php @@ -50,7 +50,8 @@ function wp_underscore_audio_template() { function wp_underscore_video_template() { $video_types = wp_get_video_extensions(); ?> -<# var w, h, settings = wp.media.view.settings, +<# var w_rule = '', h_rule = '', + w, h, settings = wp.media.view.settings, isYouTube = ! _.isEmpty( data.model.src ) && data.model.src.match(/youtube|youtu\.be/); if ( settings.contentWidth && data.model.width >= settings.contentWidth ) { @@ -64,12 +65,20 @@ function wp_underscore_video_template() { } else { h = data.model.height; } + + if ( w ) { + w_rule = ' width: ' + w + 'px;'; + } + + if ( h ) { + h_rule = ' height: ' + h + 'px;'; + } #> -
+
- <# } else if ( 'video' === data.type ) { #> -
+ <# } else if ( 'video' === data.type ) { + var w_rule = h_rule = ''; + if ( data.width ) { + w_rule = ' width: ' + data.width + 'px;'; + } else if ( wp.media.view.settings.contentWidth ) { + w_rule = ' width: ' + wp.media.view.settings.contentWidth + 'px;'; + } + if ( data.height ) { + h_rule = ' height: ' + data.height + 'px;'; + } + #> +
diff --git a/wp-includes/media.php b/wp-includes/media.php index eb5cf2c10e..09853648de 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1874,7 +1874,14 @@ function wp_video_shortcode( $attr, $content = '' ) { } $html .= ''; - $output = sprintf( '
%s
', $atts['width'], $html ); + $width_rule = $height_rule = ''; + if ( ! empty( $atts['width'] ) ) { + $width_rule = sprintf( ' width: %dpx;', $atts['width'] ); + } + if ( ! empty( $atts['height'] ) ) { + $height_rule = sprintf( ' height: %dpx;', $atts['height'] ); + } + $output = sprintf( '
%s
', $width_rule, $height_rule, $html ); /** * Filter the output of the video shortcode. diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index d555a4fb8d..c736e3167d 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -1520,6 +1520,9 @@ function prepend_attachment($content) { $atts['width'] = (int) $meta['width']; $atts['height'] = (int) $meta['height']; } + if ( has_post_thumbnail() ) { + $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() ); + } $p = wp_video_shortcode( $atts ); } elseif ( 0 === strpos( $post->post_mime_type, 'audio' ) ) { $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );