Make WordPress Core

Changeset 42691


Ignore:
Timestamp:
02/11/2018 02:43:40 PM (9 years ago)
Author:
SergeyBiryukov
Message:

Media: Add aria-describedby to img_caption_shortcode() output to improve image/caption relationship.

Props joedolson.
Fixes #34595.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r42690 r42691  
    15581558
    15591559        if ( ! empty( $atts['id'] ) ) {
    1560                 $atts['id'] = 'id="' . esc_attr( sanitize_html_class( $atts['id'] ) ) . '" ';
    1561         }
     1560                $att_id     = esc_attr( sanitize_html_class( $atts['id'] ) );
     1561                $atts['id'] = 'id="' . $att_id . '" ';
     1562        }
     1563
     1564        $caption_id = 'caption-' . str_replace( '_', '-', $att_id );
    15621565
    15631566        $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
    … …  
    15911594        if ( $html5 ) {
    15921595                $html = sprintf(
    1593                         '<figure %s%sclass="%s">%s%s</figure>',
     1596                        '<figure %s%sclass="%s" aria-describedby="%s">%s%s</figure>',
    15941597                        $atts['id'],
    15951598                        $style,
    15961599                        esc_attr( $class ),
     1600                        $caption_id,
    15971601                        do_shortcode( $content ),
    15981602                        sprintf(
    1599                                 '<figcaption class="wp-caption-text">%s</figcaption>',
     1603                                '<figcaption id="%s" class="wp-caption-text">%s</figcaption>',
     1604                                $caption_id,
    16001605                                $atts['caption']
    16011606                        )
    … …  
    16071612                        $style,
    16081613                        esc_attr( $class ),
    1609                         do_shortcode( $content ),
     1614                        str_replace( '<img ', '<img aria-describedby="' . $caption_id . '" ', do_shortcode( $content ) ),
    16101615                        sprintf(
    1611                                 '<p class="wp-caption-text">%s</p>',
     1616                                '<p id="%s" class="wp-caption-text">%s</p>',
     1617                                $caption_id,
    16121618                                $atts['caption']
    16131619                        )
Note: See TracChangeset for help on using the changeset viewer.