Make WordPress Core

Changeset 42693


Ignore:
Timestamp:
02/11/2018 03:19:58 PM (7 years ago)
Author:
SergeyBiryukov
Message:

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

See #34595.

File:
1 edited

Legend:

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

    r42692 r42693  
    15441544    $atts = shortcode_atts(
    15451545        array(
    1546             'id'      => '',
    1547             'align'   => 'alignnone',
    1548             'width'   => '',
    1549             'caption' => '',
    1550             'class'   => '',
     1546            'id'         => '',
     1547            'caption_id' => '',
     1548            'align'      => 'alignnone',
     1549            'width'      => '',
     1550            'caption'    => '',
     1551            'class'      => '',
    15511552        ), $attr, 'caption'
    15521553    );
     
    15571558    }
    15581559
    1559     $caption_id = '';
    1560 
    1561     if ( ! empty( $atts['id'] ) ) {
     1560    if ( $atts['id'] ) {
    15621561        $att_id     = esc_attr( sanitize_html_class( $atts['id'] ) );
    15631562        $atts['id'] = 'id="' . $att_id . '" ';
    1564         $caption_id = 'caption-' . str_replace( '_', '-', $att_id );
     1563
     1564        if ( ! $atts['caption_id'] ) {
     1565            $atts['caption_id'] = 'caption-' . str_replace( '_', '-', $att_id );
     1566        }
     1567    }
     1568
     1569    $describedby = '';
     1570
     1571    if ( $atts['caption_id'] ) {
     1572        $describedby        = 'aria-describedby="' . $atts['caption_id'] . '" ';
     1573        $atts['caption_id'] = 'id="' . $atts['caption_id'] . '" ';
    15651574    }
    15661575
     
    15951604    if ( $html5 ) {
    15961605        $html = sprintf(
    1597             '<figure %s%sclass="%s" aria-describedby="%s">%s%s</figure>',
     1606            '<figure %s%s%sclass="%s">%s%s</figure>',
    15981607            $atts['id'],
     1608            $describedby,
    15991609            $style,
    16001610            esc_attr( $class ),
    1601             $caption_id,
    16021611            do_shortcode( $content ),
    16031612            sprintf(
    1604                 '<figcaption id="%s" class="wp-caption-text">%s</figcaption>',
    1605                 $caption_id,
     1613                '<figcaption %sclass="wp-caption-text">%s</figcaption>',
     1614                $atts['caption_id'],
    16061615                $atts['caption']
    16071616            )
     
    16131622            $style,
    16141623            esc_attr( $class ),
    1615             str_replace( '<img ', '<img aria-describedby="' . $caption_id . '" ', do_shortcode( $content ) ),
     1624            str_replace( '<img ', '<img ' . $describedby, do_shortcode( $content ) ),
    16161625            sprintf(
    16171626                '<p id="%s" class="wp-caption-text">%s</p>',
    1618                 $caption_id,
     1627                $atts['caption_id'],
    16191628                $atts['caption']
    16201629            )
Note: See TracChangeset for help on using the changeset viewer.