Media: Pass original attribute values to `img_caption_shortcode_width` filter instead of markup pieces.

Add `caption_id` to the list of documented `[caption]` shortcode attributes.

See #34595.
Built from https://develop.svn.wordpress.org/trunk@42704


git-svn-id: http://core.svn.wordpress.org/trunk@42532 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2018-02-12 21:37:30 +00:00
parent 0a97d79899
commit 0f8d7de77d
2 changed files with 25 additions and 20 deletions

View File

@ -1493,20 +1493,23 @@ add_shortcode( 'caption', 'img_caption_shortcode' );
* filter is {@see 'img_caption_shortcode'} and passes an empty string, the attr * filter is {@see 'img_caption_shortcode'} and passes an empty string, the attr
* parameter and the content parameter values. * parameter and the content parameter values.
* *
* The supported attributes for the shortcode are 'id', 'align', 'width', and * The supported attributes for the shortcode are 'id', 'caption_id', 'align',
* 'caption'. * 'width', 'caption', and 'class'.
* *
* @since 2.6.0 * @since 2.6.0
* @since 3.9.0 The `class` attribute was added.
* @since 5.0.0 The `caption_id` attribute was added.
* *
* @param array $attr { * @param array $attr {
* Attributes of the caption shortcode. * Attributes of the caption shortcode.
* *
* @type string $id ID of the div element for the caption. * @type string $id ID of the image and caption container element, i.e. <figure> or <div>.
* @type string $align Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft', * @type string $caption_id ID of the caption element, i.e. <figcaption> or <p>.
* 'aligncenter', alignright', 'alignnone'. * @type string $align Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft',
* @type int $width The width of the caption, in pixels. * 'aligncenter', alignright', 'alignnone'.
* @type string $caption The caption text. * @type int $width The width of the caption, in pixels.
* @type string $class Additional class name(s) added to the caption container. * @type string $caption The caption text.
* @type string $class Additional class name(s) added to the caption container.
* } * }
* @param string $content Shortcode content. * @param string $content Shortcode content.
* @return string HTML content to display the caption. * @return string HTML content to display the caption.
@ -1558,19 +1561,21 @@ function img_caption_shortcode( $attr, $content = null ) {
} }
if ( $atts['id'] ) { if ( $atts['id'] ) {
$att_id = esc_attr( sanitize_html_class( $atts['id'] ) ); $atts['id'] = sanitize_html_class( $atts['id'] );
$atts['id'] = 'id="' . $att_id . '" '; $id = 'id="' . esc_attr( $atts['id'] ) . '" ';
}
if ( ! $atts['caption_id'] ) { if ( $atts['caption_id'] ) {
$atts['caption_id'] = 'caption-' . str_replace( '_', '-', $att_id ); $atts['caption_id'] = sanitize_html_class( $atts['caption_id'] );
} } elseif ( $atts['id'] ) {
$atts['caption_id'] = 'caption-' . str_replace( '_', '-', $atts['id'] );
} }
$describedby = ''; $describedby = '';
if ( $atts['caption_id'] ) { if ( $atts['caption_id'] ) {
$describedby = 'aria-describedby="' . $atts['caption_id'] . '" '; $caption_id = 'id="' . esc_attr( $atts['caption_id'] ) . '" ';
$atts['caption_id'] = 'id="' . $atts['caption_id'] . '" '; $describedby = 'aria-describedby="' . esc_attr( $atts['caption_id'] ) . '" ';
} }
$class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] ); $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
@ -1604,27 +1609,27 @@ function img_caption_shortcode( $attr, $content = null ) {
if ( $html5 ) { if ( $html5 ) {
$html = sprintf( $html = sprintf(
'<figure %s%s%sclass="%s">%s%s</figure>', '<figure %s%s%sclass="%s">%s%s</figure>',
$atts['id'], $id,
$describedby, $describedby,
$style, $style,
esc_attr( $class ), esc_attr( $class ),
do_shortcode( $content ), do_shortcode( $content ),
sprintf( sprintf(
'<figcaption %sclass="wp-caption-text">%s</figcaption>', '<figcaption %sclass="wp-caption-text">%s</figcaption>',
$atts['caption_id'], $caption_id,
$atts['caption'] $atts['caption']
) )
); );
} else { } else {
$html = sprintf( $html = sprintf(
'<div %s%sclass="%s">%s%s</div>', '<div %s%sclass="%s">%s%s</div>',
$atts['id'], $id,
$style, $style,
esc_attr( $class ), esc_attr( $class ),
str_replace( '<img ', '<img ' . $describedby, do_shortcode( $content ) ), str_replace( '<img ', '<img ' . $describedby, do_shortcode( $content ) ),
sprintf( sprintf(
'<p %sclass="wp-caption-text">%s</p>', '<p %sclass="wp-caption-text">%s</p>',
$atts['caption_id'], $caption_id,
$atts['caption'] $atts['caption']
) )
); );

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.0-alpha-42703'; $wp_version = '5.0-alpha-42704';
/** /**
* 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.