WordPress.org

Make WordPress Core

Ticket #34595: 34595.patch

File 34595.patch, 1.5 KB (added by joedolson, 4 years ago)

Adds aria-describedby to captioned images

  • wp-includes/media.php

     
    13971397        if ( $atts['width'] < 1 || empty( $atts['caption'] ) )
    13981398                return $content;
    13991399
    1400         if ( ! empty( $atts['id'] ) )
    1401                 $atts['id'] = 'id="' . esc_attr( sanitize_html_class( $atts['id'] ) ) . '" ';
     1400        if ( ! empty( $atts['id'] ) ) {
     1401                $att_id     = esc_attr( sanitize_html_class( $atts['id'] ) );
     1402                $atts['id'] = 'id="' . $att_id . '" ';
     1403        }
    14021404
    14031405        $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
    14041406
     
    14291431
    14301432        $html = '';
    14311433        if ( $html5 ) {
    1432                 $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
    1433                 . do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
     1434                $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '"' . 'aria-describedby="caption-' . $att_id . '">'
     1435                . do_shortcode( $content ) . '<figcaption class="wp-caption-text" id="caption-' . $att_id .'">' . $atts['caption'] . '</figcaption></figure>';
    14341436        } else {
    14351437                $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
    1436                 . do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
     1438                . str_replace( '<img', '<img aria-describedby="caption-' . $att_id . '"', do_shortcode( $content ) ) . '<p class="wp-caption-text" id="caption-' . $att_id .'">' . $atts['caption'] . '</p></div>';
    14371439        }
    14381440
    14391441        return $html;