Media: Only add `aria-describedby` in `img_caption_shortcode()` if a non-empty attachment ID attribute was provided.

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


git-svn-id: http://core.svn.wordpress.org/trunk@42521 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2018-02-11 15:20:30 +00:00
parent dffe5deb97
commit 0f2b559d05
2 changed files with 25 additions and 16 deletions

View File

@ -1543,11 +1543,12 @@ function img_caption_shortcode( $attr, $content = null ) {
$atts = shortcode_atts( $atts = shortcode_atts(
array( array(
'id' => '', 'id' => '',
'align' => 'alignnone', 'caption_id' => '',
'width' => '', 'align' => 'alignnone',
'caption' => '', 'width' => '',
'class' => '', 'caption' => '',
'class' => '',
), $attr, 'caption' ), $attr, 'caption'
); );
@ -1556,12 +1557,20 @@ function img_caption_shortcode( $attr, $content = null ) {
return $content; return $content;
} }
$caption_id = ''; if ( $atts['id'] ) {
if ( ! empty( $atts['id'] ) ) {
$att_id = esc_attr( sanitize_html_class( $atts['id'] ) ); $att_id = esc_attr( sanitize_html_class( $atts['id'] ) );
$atts['id'] = 'id="' . $att_id . '" '; $atts['id'] = 'id="' . $att_id . '" ';
$caption_id = 'caption-' . str_replace( '_', '-', $att_id );
if ( ! $atts['caption_id'] ) {
$atts['caption_id'] = 'caption-' . str_replace( '_', '-', $att_id );
}
}
$describedby = '';
if ( $atts['caption_id'] ) {
$describedby = 'aria-describedby="' . $atts['caption_id'] . '" ';
$atts['caption_id'] = 'id="' . $atts['caption_id'] . '" ';
} }
$class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] ); $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
@ -1594,15 +1603,15 @@ function img_caption_shortcode( $attr, $content = null ) {
if ( $html5 ) { if ( $html5 ) {
$html = sprintf( $html = sprintf(
'<figure %s%sclass="%s" aria-describedby="%s">%s%s</figure>', '<figure %s%s%sclass="%s">%s%s</figure>',
$atts['id'], $atts['id'],
$describedby,
$style, $style,
esc_attr( $class ), esc_attr( $class ),
$caption_id,
do_shortcode( $content ), do_shortcode( $content ),
sprintf( sprintf(
'<figcaption id="%s" class="wp-caption-text">%s</figcaption>', '<figcaption %sclass="wp-caption-text">%s</figcaption>',
$caption_id, $atts['caption_id'],
$atts['caption'] $atts['caption']
) )
); );
@ -1612,10 +1621,10 @@ function img_caption_shortcode( $attr, $content = null ) {
$atts['id'], $atts['id'],
$style, $style,
esc_attr( $class ), esc_attr( $class ),
str_replace( '<img ', '<img aria-describedby="' . $caption_id . '" ', do_shortcode( $content ) ), str_replace( '<img ', '<img ' . $describedby, do_shortcode( $content ) ),
sprintf( sprintf(
'<p id="%s" class="wp-caption-text">%s</p>', '<p id="%s" class="wp-caption-text">%s</p>',
$caption_id, $atts['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-42692'; $wp_version = '5.0-alpha-42693';
/** /**
* 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.