From b836d650bd16f8e2570353aba5928379b8eb8616 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 19 Mar 2014 19:00:14 +0000 Subject: [PATCH] On attachment pages for audio and video, display players. Currently, only a link is displayed. Add minimal CSS rules for compatibility with 2011, 2012, and 2013 themes. In `prepend_attachment`, add logic to support attachment types that are not `image`. In `get_post_class()`, don't add the `has-post-thumbnail` class for attachment pages. Fixes #27243. Built from https://develop.svn.wordpress.org/trunk@27622 git-svn-id: http://core.svn.wordpress.org/trunk@27465 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-content/themes/twentyeleven/style.css | 12 +++++++++++ wp-content/themes/twentythirteen/style.css | 12 +++++++++++ wp-content/themes/twentytwelve/style.css | 11 +++++++++++ wp-includes/post-template.php | 23 +++++++++++++++++----- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/wp-content/themes/twentyeleven/style.css b/wp-content/themes/twentyeleven/style.css index 7c9cb3ce96..4df95c5257 100644 --- a/wp-content/themes/twentyeleven/style.css +++ b/wp-content/themes/twentyeleven/style.css @@ -1706,6 +1706,18 @@ section.recent-posts .other-recent-posts li:after { text-transform: uppercase; } +/* =Media +-------------------------------------------------------------- */ + +audio, +video { + display: inline-block; + max-width: 100%; +} + +.attachment .entry-content .mejs-container { + margin-bottom: 24px; +} /* =Navigation -------------------------------------------------------------- */ diff --git a/wp-content/themes/twentythirteen/style.css b/wp-content/themes/twentythirteen/style.css index 975d68083d..a78cb9a0d0 100644 --- a/wp-content/themes/twentythirteen/style.css +++ b/wp-content/themes/twentythirteen/style.css @@ -1837,6 +1837,18 @@ footer.entry-meta { display: none; } +.attachment .entry-content .mejs-audio { + max-width: 400px; + margin: 0 auto; +} + +.attachment .entry-content .wp-video { + margin: 0 auto; +} + +.attachment .entry-content .mejs-container { + margin-bottom: 24px; +} /** * 5.7 Post/Paging Navigation diff --git a/wp-content/themes/twentytwelve/style.css b/wp-content/themes/twentytwelve/style.css index 7fb30fff08..93cd07fd5c 100644 --- a/wp-content/themes/twentytwelve/style.css +++ b/wp-content/themes/twentytwelve/style.css @@ -1007,6 +1007,17 @@ footer.entry-meta { margin-top: 1.571428571rem; } +/* =Single audio/video attachment view +-------------------------------------------------------------- */ + +.attachment .entry-content .mejs-audio { + max-width: 400px; +} + +.attachment .entry-content .mejs-container { + margin-bottom: 24px; +} + /* =Single image attachment view -------------------------------------------------------------- */ diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index fcc75f934e..c078b8a6df 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -347,7 +347,7 @@ function get_post_class( $class = '', $post_id = null ) { if ( post_password_required( $post->ID ) ) { $classes[] = 'post-password-required'; // Post thumbnails - } elseif ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) { + } elseif ( ! is_attachment( $post ) && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) { $classes[] = 'has-post-thumbnail'; } @@ -1241,10 +1241,23 @@ function prepend_attachment($content) { if ( empty($post->post_type) || $post->post_type != 'attachment' ) return $content; - $p = '

'; - // show the medium sized image representation of the attachment if available, and link to the raw file - $p .= wp_get_attachment_link(0, 'medium', false); - $p .= '

'; + if ( wp_attachment_is_image() ): + $p = '

'; + // show the medium sized image representation of the attachment if available, and link to the raw file + $p .= wp_get_attachment_link(0, 'medium', false); + $p .= '

'; + elseif ( 0 === strpos( $post->post_mime_type, 'video' ) ): + $meta = wp_get_attachment_metadata( get_the_ID() ); + $atts = array( 'src' => wp_get_attachment_url() ); + if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { + $atts['width'] = (int) $meta['width']; + $atts['height'] = (int) $meta['height']; + } + $p = wp_video_shortcode( $atts ); + elseif ( 0 === strpos( $post->post_mime_type, 'audio' ) ): + $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) ); + endif; + $p = apply_filters('prepend_attachment', $p); return "$p\n$content";