Make WordPress Core


Ignore:
Timestamp:
02/12/2018 09:36:36 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Media: Pass original attribute values to img_caption_shortcode_width filter instead of markup pieces.

Add caption_id to the list of documented [caption] shortcode attributes.

See #34595.

File:
1 edited

Legend:

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

    r42697 r42704  
    14941494 * parameter and the content parameter values.
    14951495 *
    1496  * The supported attributes for the shortcode are 'id', 'align', 'width', and
    1497  * 'caption'.
     1496 * The supported attributes for the shortcode are 'id', 'caption_id', 'align',
     1497 * 'width', 'caption', and 'class'.
    14981498 *
    14991499 * @since 2.6.0
     1500 * @since 3.9.0 The `class` attribute was added.
     1501 * @since 5.0.0 The `caption_id` attribute was added.
    15001502 *
    15011503 * @param array  $attr {
    15021504 *     Attributes of the caption shortcode.
    15031505 *
    1504  *     @type string $id      ID of the div element for the caption.
    1505  *     @type string $align   Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft',
    1506  *                           'aligncenter', alignright', 'alignnone'.
    1507  *     @type int    $width   The width of the caption, in pixels.
    1508  *     @type string $caption The caption text.
    1509  *     @type string $class   Additional class name(s) added to the caption container.
     1506 *     @type string $id         ID of the image and caption container element, i.e. <figure> or <div>.
     1507 *     @type string $caption_id ID of the caption element, i.e. <figcaption> or <p>.
     1508 *     @type string $align      Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft',
     1509 *                              'aligncenter', alignright', 'alignnone'.
     1510 *     @type int    $width      The width of the caption, in pixels.
     1511 *     @type string $caption    The caption text.
     1512 *     @type string $class      Additional class name(s) added to the caption container.
    15101513 * }
    15111514 * @param string $content Shortcode content.
     
    15591562
    15601563    if ( $atts['id'] ) {
    1561         $att_id     = esc_attr( sanitize_html_class( $atts['id'] ) );
    1562         $atts['id'] = 'id="' . $att_id . '" ';
    1563 
    1564         if ( ! $atts['caption_id'] ) {
    1565             $atts['caption_id'] = 'caption-' . str_replace( '_', '-', $att_id );
    1566         }
     1564        $atts['id'] = sanitize_html_class( $atts['id'] );
     1565        $id         = 'id="' . esc_attr( $atts['id'] ) . '" ';
     1566    }
     1567
     1568    if ( $atts['caption_id'] ) {
     1569        $atts['caption_id'] = sanitize_html_class( $atts['caption_id'] );
     1570    } elseif ( $atts['id'] ) {
     1571        $atts['caption_id'] = 'caption-' . str_replace( '_', '-', $atts['id'] );
    15671572    }
    15681573
     
    15701575
    15711576    if ( $atts['caption_id'] ) {
    1572         $describedby        = 'aria-describedby="' . $atts['caption_id'] . '" ';
    1573         $atts['caption_id'] = 'id="' . $atts['caption_id'] . '" ';
     1577        $caption_id  = 'id="' . esc_attr( $atts['caption_id'] ) . '" ';
     1578        $describedby = 'aria-describedby="' . esc_attr( $atts['caption_id'] ) . '" ';
    15741579    }
    15751580
     
    16051610        $html = sprintf(
    16061611            '<figure %s%s%sclass="%s">%s%s</figure>',
    1607             $atts['id'],
     1612            $id,
    16081613            $describedby,
    16091614            $style,
     
    16121617            sprintf(
    16131618                '<figcaption %sclass="wp-caption-text">%s</figcaption>',
    1614                 $atts['caption_id'],
     1619                $caption_id,
    16151620                $atts['caption']
    16161621            )
     
    16191624        $html = sprintf(
    16201625            '<div %s%sclass="%s">%s%s</div>',
    1621             $atts['id'],
     1626            $id,
    16221627            $style,
    16231628            esc_attr( $class ),
     
    16251630            sprintf(
    16261631                '<p %sclass="wp-caption-text">%s</p>',
    1627                 $atts['caption_id'],
     1632                $caption_id,
    16281633                $atts['caption']
    16291634            )
Note: See TracChangeset for help on using the changeset viewer.