Make WordPress Core

Ticket #31053: 31053.diff

File 31053.diff, 1.7 KB (added by joemcgill, 10 years ago)

Adds support for 'img_caption_shortcode_width' filter on HTML5 captions

  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 9bf83bb..a7b7ab1 100644
    function img_caption_shortcode( $attr, $content = null ) { 
    900900
    901901        $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
    902902
    903         if ( current_theme_supports( 'html5', 'caption' ) ) {
    904                 return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr( $class ) . '">'
    905                 . do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    906         }
    907 
    908         $caption_width = 10 + $atts['width'];
     903        // HTML5 captions never added the extra 10px to the image width
     904        $caption_width = current_theme_supports( 'html5', 'caption' ) ? $atts['width'] : 10 + $atts['width'];
    909905
    910906        /**
    911907         * Filter the width of an image's caption.
    function img_caption_shortcode( $attr, $content = null ) { 
    928924        if ( $caption_width )
    929925                $style = 'style="width: ' . (int) $caption_width . 'px" ';
    930926
    931         return '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
    932         . do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
     927        $html = '';
     928        if ( current_theme_supports( 'html5', 'caption' ) ) {
     929                $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
     930                . do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
     931        } else {
     932                $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
     933                . do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
     934        }
     935
     936        return $html;
    933937}
    934938
    935939add_shortcode('gallery', 'gallery_shortcode');