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

Props joemcgill.
Fixes #31053.

Built from https://develop.svn.wordpress.org/trunk@34261


git-svn-id: http://core.svn.wordpress.org/trunk@34225 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-09-17 06:04:24 +00:00
parent f3dd19c6e2
commit 1f3dce8c75
2 changed files with 20 additions and 15 deletions

View File

@ -909,12 +909,9 @@ function img_caption_shortcode( $attr, $content = null ) {
$class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] ); $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
if ( current_theme_supports( 'html5', 'caption' ) ) { $html5 = current_theme_supports( 'html5', 'caption' );
return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr( $class ) . '">' // HTML5 captions never added the extra 10px to the image width
. do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>'; $width = $html5 ? $atts['width'] : ( 10 + $atts['width'] );
}
$caption_width = 10 + $atts['width'];
/** /**
* Filter the width of an image's caption. * Filter the width of an image's caption.
@ -926,21 +923,29 @@ function img_caption_shortcode( $attr, $content = null ) {
* *
* @see img_caption_shortcode() * @see img_caption_shortcode()
* *
* @param int $caption_width Width of the caption in pixels. To remove this inline style, * @param int $width Width of the caption in pixels. To remove this inline style,
* return zero. * return zero.
* @param array $atts Attributes of the caption shortcode. * @param array $atts Attributes of the caption shortcode.
* @param string $content The image element, possibly wrapped in a hyperlink. * @param string $content The image element, possibly wrapped in a hyperlink.
*/ */
$caption_width = apply_filters( 'img_caption_shortcode_width', $caption_width, $atts, $content ); $caption_width = apply_filters( 'img_caption_shortcode_width', $width, $atts, $content );
$style = ''; $style = '';
if ( $caption_width ) if ( $caption_width )
$style = 'style="width: ' . (int) $caption_width . 'px" '; $style = 'style="width: ' . (int) $caption_width . 'px" ';
return '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">' $html = '';
if ( $html5 ) {
$html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
. do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
} else {
$html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>'; . do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
} }
return $html;
}
add_shortcode('gallery', 'gallery_shortcode'); add_shortcode('gallery', 'gallery_shortcode');
/** /**

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-alpha-34260'; $wp_version = '4.4-alpha-34261';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.