Add a 6th (!) attribute to `wp_get_attachment_link()` to allow `aria-describedby` to be added to gallery output.

Props joedolson, DrewAPicture, rianrietveld.
Fixes #27402.

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


git-svn-id: http://core.svn.wordpress.org/trunk@29667 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-10-16 04:28:17 +00:00
parent 1470990892
commit 72d12b514d
2 changed files with 13 additions and 9 deletions

View File

@ -1056,12 +1056,14 @@ function gallery_shortcode( $attr ) {
$i = 0; $i = 0;
foreach ( $attachments as $id => $attachment ) { foreach ( $attachments as $id => $attachment ) {
$attr = ( trim( $attachment->post_excerpt ) ) ? array( 'aria-describedby' => "$selector-$id" ) : '';
if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) { if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) {
$image_output = wp_get_attachment_link( $id, $atts['size'], false, false ); $image_output = wp_get_attachment_link( $id, $atts['size'], false, false, $attr );
} elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) { } elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) {
$image_output = wp_get_attachment_image( $id, $atts['size'], false ); $image_output = wp_get_attachment_image( $id, $atts['size'], false, $attr );
} else { } else {
$image_output = wp_get_attachment_link( $id, $atts['size'], true, false ); $image_output = wp_get_attachment_link( $id, $atts['size'], true, false, false, $attr );
} }
$image_meta = wp_get_attachment_metadata( $id ); $image_meta = wp_get_attachment_metadata( $id );
@ -1076,7 +1078,7 @@ function gallery_shortcode( $attr ) {
</{$icontag}>"; </{$icontag}>";
if ( $captiontag && trim($attachment->post_excerpt) ) { if ( $captiontag && trim($attachment->post_excerpt) ) {
$output .= " $output .= "
<{$captiontag} class='wp-caption-text gallery-caption'> <{$captiontag} class='wp-caption-text gallery-caption' id='$selector-$id'>
" . wptexturize($attachment->post_excerpt) . " " . wptexturize($attachment->post_excerpt) . "
</{$captiontag}>"; </{$captiontag}>";
} }

View File

@ -1462,9 +1462,10 @@ function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $
* @param bool $permalink Optional, default is false. Whether to add permalink to image. * @param bool $permalink Optional, default is false. Whether to add permalink to image.
* @param bool $icon Optional, default is false. Whether to include icon. * @param bool $icon Optional, default is false. Whether to include icon.
* @param string|bool $text Optional, default is false. If string, then will be link text. * @param string|bool $text Optional, default is false. If string, then will be link text.
* @param array|string $attr Optional. Array or string of attributes.
* @return string HTML content. * @return string HTML content.
*/ */
function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) { function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
$id = intval( $id ); $id = intval( $id );
$_post = get_post( $id ); $_post = get_post( $id );
@ -1474,12 +1475,13 @@ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = fals
if ( $permalink ) if ( $permalink )
$url = get_attachment_link( $_post->ID ); $url = get_attachment_link( $_post->ID );
if ( $text ) if ( $text ) {
$link_text = $text; $link_text = $text;
elseif ( $size && 'none' != $size ) } elseif ( $size && 'none' != $size ) {
$link_text = wp_get_attachment_image( $id, $size, $icon ); $link_text = wp_get_attachment_image( $id, $size, $icon, $attr );
else } else {
$link_text = ''; $link_text = '';
}
if ( trim( $link_text ) == '' ) if ( trim( $link_text ) == '' )
$link_text = $_post->post_title; $link_text = $_post->post_title;