Make WordPress Core

Changeset 34261


Ignore:
Timestamp:
09/17/2015 06:03:11 AM (9 years ago)
Author:
wonderboymusic
Message:

Media: Ensure that HTML5 captions apply the 'img_caption_shortcode_width'.

Props joemcgill.
Fixes #31053.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r34258 r34261  
    910910    $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
    911911
    912     if ( current_theme_supports( 'html5', 'caption' ) ) {
    913         return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr( $class ) . '">'
    914         . do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    915     }
    916 
    917     $caption_width = 10 + $atts['width'];
     912    $html5 = current_theme_supports( 'html5', 'caption' );
     913    // HTML5 captions never added the extra 10px to the image width
     914    $width = $html5 ? $atts['width'] : ( 10 + $atts['width'] );
    918915
    919916    /**
     
    927924     * @see img_caption_shortcode()
    928925     *
    929      * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
    930      *                              return zero.
    931      * @param array  $atts          Attributes of the caption shortcode.
    932      * @param string $content       The image element, possibly wrapped in a hyperlink.
    933      */
    934     $caption_width = apply_filters( 'img_caption_shortcode_width', $caption_width, $atts, $content );
     926     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     927     *                         return zero.
     928     * @param array  $atts     Attributes of the caption shortcode.
     929     * @param string $content  The image element, possibly wrapped in a hyperlink.
     930     */
     931    $caption_width = apply_filters( 'img_caption_shortcode_width', $width, $atts, $content );
    935932
    936933    $style = '';
     
    938935        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    939936
    940     return '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
    941     . do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
     937    $html = '';
     938    if ( $html5 ) {
     939        $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
     940        . do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
     941    } else {
     942        $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
     943        . do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
     944    }
     945
     946    return $html;
    942947}
    943948
     
    27792784
    27802785    $attached_file = get_attached_file( $attachment->ID );
    2781    
     2786
    27822787    if ( isset( $meta['filesize'] ) ) {
    27832788        $bytes = $meta['filesize'];
Note: See TracChangeset for help on using the changeset viewer.