From 0f8d7de77d9782c48fdfe64ec8555a967bc7c9e2 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 12 Feb 2018 21:37:30 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@42704 git-svn-id: http://core.svn.wordpress.org/trunk@42532 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 43 +++++++++++++++++++++++------------------ wp-includes/version.php | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index dcbf8a22ff..f92ecbd1c7 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1493,20 +1493,23 @@ add_shortcode( 'caption', 'img_caption_shortcode' ); * filter is {@see 'img_caption_shortcode'} and passes an empty string, the attr * parameter and the content parameter values. * - * The supported attributes for the shortcode are 'id', 'align', 'width', and - * 'caption'. + * The supported attributes for the shortcode are 'id', 'caption_id', 'align', + * 'width', 'caption', and 'class'. * * @since 2.6.0 + * @since 3.9.0 The `class` attribute was added. + * @since 5.0.0 The `caption_id` attribute was added. * * @param array $attr { * Attributes of the caption shortcode. * - * @type string $id ID of the div element for the caption. - * @type string $align Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft', - * 'aligncenter', alignright', 'alignnone'. - * @type int $width The width of the caption, in pixels. - * @type string $caption The caption text. - * @type string $class Additional class name(s) added to the caption container. + * @type string $id ID of the image and caption container element, i.e.
or
. + * @type string $caption_id ID of the caption element, i.e.
or

. + * @type string $align Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft', + * 'aligncenter', alignright', 'alignnone'. + * @type int $width The width of the caption, in pixels. + * @type string $caption The caption text. + * @type string $class Additional class name(s) added to the caption container. * } * @param string $content Shortcode content. * @return string HTML content to display the caption. @@ -1558,19 +1561,21 @@ function img_caption_shortcode( $attr, $content = null ) { } if ( $atts['id'] ) { - $att_id = esc_attr( sanitize_html_class( $atts['id'] ) ); - $atts['id'] = 'id="' . $att_id . '" '; + $atts['id'] = sanitize_html_class( $atts['id'] ); + $id = 'id="' . esc_attr( $atts['id'] ) . '" '; + } - if ( ! $atts['caption_id'] ) { - $atts['caption_id'] = 'caption-' . str_replace( '_', '-', $att_id ); - } + if ( $atts['caption_id'] ) { + $atts['caption_id'] = sanitize_html_class( $atts['caption_id'] ); + } elseif ( $atts['id'] ) { + $atts['caption_id'] = 'caption-' . str_replace( '_', '-', $atts['id'] ); } $describedby = ''; if ( $atts['caption_id'] ) { - $describedby = 'aria-describedby="' . $atts['caption_id'] . '" '; - $atts['caption_id'] = 'id="' . $atts['caption_id'] . '" '; + $caption_id = 'id="' . esc_attr( $atts['caption_id'] ) . '" '; + $describedby = 'aria-describedby="' . esc_attr( $atts['caption_id'] ) . '" '; } $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] ); @@ -1604,27 +1609,27 @@ function img_caption_shortcode( $attr, $content = null ) { if ( $html5 ) { $html = sprintf( '

%s%s
', - $atts['id'], + $id, $describedby, $style, esc_attr( $class ), do_shortcode( $content ), sprintf( '
%s
', - $atts['caption_id'], + $caption_id, $atts['caption'] ) ); } else { $html = sprintf( '
%s%s
', - $atts['id'], + $id, $style, esc_attr( $class ), str_replace( '%s

', - $atts['caption_id'], + $caption_id, $atts['caption'] ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 840e75174f..91a8d44412 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-alpha-42703'; +$wp_version = '5.0-alpha-42704'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.