From 0f2b559d05a87d2e8c42a5c9a2381de9085bdaba Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 11 Feb 2018 15:20:30 +0000 Subject: [PATCH] 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 --- wp-includes/media.php | 39 ++++++++++++++++++++++++--------------- wp-includes/version.php | 2 +- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 1da6dcecd1..68ac031298 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1543,11 +1543,12 @@ function img_caption_shortcode( $attr, $content = null ) { $atts = shortcode_atts( array( - 'id' => '', - 'align' => 'alignnone', - 'width' => '', - 'caption' => '', - 'class' => '', + 'id' => '', + 'caption_id' => '', + 'align' => 'alignnone', + 'width' => '', + 'caption' => '', + 'class' => '', ), $attr, 'caption' ); @@ -1556,12 +1557,20 @@ function img_caption_shortcode( $attr, $content = null ) { return $content; } - $caption_id = ''; - - if ( ! empty( $atts['id'] ) ) { + if ( $atts['id'] ) { $att_id = esc_attr( sanitize_html_class( $atts['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'] ); @@ -1594,15 +1603,15 @@ function img_caption_shortcode( $attr, $content = null ) { if ( $html5 ) { $html = sprintf( - '
%s%s
', + '
%s%s
', $atts['id'], + $describedby, $style, esc_attr( $class ), - $caption_id, do_shortcode( $content ), sprintf( - '
%s
', - $caption_id, + '
%s
', + $atts['caption_id'], $atts['caption'] ) ); @@ -1612,10 +1621,10 @@ function img_caption_shortcode( $attr, $content = null ) { $atts['id'], $style, esc_attr( $class ), - str_replace( '%s

', - $caption_id, + $atts['caption_id'], $atts['caption'] ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 9253ef822c..f1e9143a51 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @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.