img_caption_shortcode

The timeline below displays how wordpress function img_caption_shortcode has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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', 'caption_id', 'align',
 * 'width', 'caption', and 'class'.
 *
 * @since 2.6.0
 * @since 3.9.0 The `class` attribute was added.
 * @since 5.1.0 The `caption_id` attribute was added.
 * @since 5.9.0 The `$content` parameter default value changed from `null` to `''`.
 *
 * @param array  $attr {
 *     Attributes of the caption shortcode.
 *
 *     @type string $id         ID of the image and caption container element, i.e. `<figure>` or `<div>`.
 *     @type string $caption_id ID of the caption element, i.e. `<figcaption>` or `<p>`.
 *     @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 Optional. Shortcode content. Default empty string.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = '')
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (str_contains($attr['caption'], '<')) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if (!empty($output)) {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'caption_id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    $id = '';
    $caption_id = '';
    $describedby = '';
    if ($atts['id']) {
        $atts['id'] = sanitize_html_class($atts['id']);
        $id = 'id="' . esc_attr($atts['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']);
    }
    if ($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']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width.
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = sprintf('<figure %s%s%sclass="%s">%s%s</figure>', $id, $describedby, $style, esc_attr($class), do_shortcode($content), sprintf('<figcaption %sclass="wp-caption-text">%s</figcaption>', $caption_id, $atts['caption']));
    } else {
        $html = sprintf('<div %s%sclass="%s">%s%s</div>', $id, $style, esc_attr($class), str_replace('<img ', '<img ' . $describedby, do_shortcode($content)), sprintf('<p %sclass="wp-caption-text">%s</p>', $caption_id, $atts['caption']));
    }
    return $html;
}

WordPress Version: 6.4

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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', 'caption_id', 'align',
 * 'width', 'caption', and 'class'.
 *
 * @since 2.6.0
 * @since 3.9.0 The `class` attribute was added.
 * @since 5.1.0 The `caption_id` attribute was added.
 * @since 5.9.0 The `$content` parameter default value changed from `null` to `''`.
 *
 * @param array  $attr {
 *     Attributes of the caption shortcode.
 *
 *     @type string $id         ID of the image and caption container element, i.e. `<figure>` or `<div>`.
 *     @type string $caption_id ID of the caption element, i.e. `<figcaption>` or `<p>`.
 *     @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 Optional. Shortcode content. Default empty string.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = '')
{
    if (!$attr) {
        $attr = array();
    }
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (str_contains($attr['caption'], '<')) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if (!empty($output)) {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'caption_id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    $id = '';
    $caption_id = '';
    $describedby = '';
    if ($atts['id']) {
        $atts['id'] = sanitize_html_class($atts['id']);
        $id = 'id="' . esc_attr($atts['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']);
    }
    if ($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']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width.
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = sprintf('<figure %s%s%sclass="%s">%s%s</figure>', $id, $describedby, $style, esc_attr($class), do_shortcode($content), sprintf('<figcaption %sclass="wp-caption-text">%s</figcaption>', $caption_id, $atts['caption']));
    } else {
        $html = sprintf('<div %s%sclass="%s">%s%s</div>', $id, $style, esc_attr($class), str_replace('<img ', '<img ' . $describedby, do_shortcode($content)), sprintf('<p %sclass="wp-caption-text">%s</p>', $caption_id, $atts['caption']));
    }
    return $html;
}

WordPress Version: 6.3

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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', 'caption_id', 'align',
 * 'width', 'caption', and 'class'.
 *
 * @since 2.6.0
 * @since 3.9.0 The `class` attribute was added.
 * @since 5.1.0 The `caption_id` attribute was added.
 * @since 5.9.0 The `$content` parameter default value changed from `null` to `''`.
 *
 * @param array  $attr {
 *     Attributes of the caption shortcode.
 *
 *     @type string $id         ID of the image and caption container element, i.e. `<figure>` or `<div>`.
 *     @type string $caption_id ID of the caption element, i.e. `<figcaption>` or `<p>`.
 *     @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 Optional. Shortcode content. Default empty string.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = '')
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (str_contains($attr['caption'], '<')) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if (!empty($output)) {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'caption_id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    $id = '';
    $caption_id = '';
    $describedby = '';
    if ($atts['id']) {
        $atts['id'] = sanitize_html_class($atts['id']);
        $id = 'id="' . esc_attr($atts['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']);
    }
    if ($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']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width.
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = sprintf('<figure %s%s%sclass="%s">%s%s</figure>', $id, $describedby, $style, esc_attr($class), do_shortcode($content), sprintf('<figcaption %sclass="wp-caption-text">%s</figcaption>', $caption_id, $atts['caption']));
    } else {
        $html = sprintf('<div %s%sclass="%s">%s%s</div>', $id, $style, esc_attr($class), str_replace('<img ', '<img ' . $describedby, do_shortcode($content)), sprintf('<p %sclass="wp-caption-text">%s</p>', $caption_id, $atts['caption']));
    }
    return $html;
}

WordPress Version: 5.9

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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', 'caption_id', 'align',
 * 'width', 'caption', and 'class'.
 *
 * @since 2.6.0
 * @since 3.9.0 The `class` attribute was added.
 * @since 5.1.0 The `caption_id` attribute was added.
 * @since 5.9.0 The `$content` parameter default value changed from `null` to `''`.
 *
 * @param array  $attr {
 *     Attributes of the caption shortcode.
 *
 *     @type string $id         ID of the image and caption container element, i.e. `<figure>` or `<div>`.
 *     @type string $caption_id ID of the caption element, i.e. `<figcaption>` or `<p>`.
 *     @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 Optional. Shortcode content. Default empty string.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = '')
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if (!empty($output)) {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'caption_id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    $id = '';
    $caption_id = '';
    $describedby = '';
    if ($atts['id']) {
        $atts['id'] = sanitize_html_class($atts['id']);
        $id = 'id="' . esc_attr($atts['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']);
    }
    if ($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']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width.
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = sprintf('<figure %s%s%sclass="%s">%s%s</figure>', $id, $describedby, $style, esc_attr($class), do_shortcode($content), sprintf('<figcaption %sclass="wp-caption-text">%s</figcaption>', $caption_id, $atts['caption']));
    } else {
        $html = sprintf('<div %s%sclass="%s">%s%s</div>', $id, $style, esc_attr($class), str_replace('<img ', '<img ' . $describedby, do_shortcode($content)), sprintf('<p %sclass="wp-caption-text">%s</p>', $caption_id, $atts['caption']));
    }
    return $html;
}

WordPress Version: 5.4

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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', 'caption_id', 'align',
 * 'width', 'caption', and 'class'.
 *
 * @since 2.6.0
 * @since 3.9.0 The `class` attribute was added.
 * @since 5.1.0 The `caption_id` attribute was added.
 *
 * @param array  $attr {
 *     Attributes of the caption shortcode.
 *
 *     @type string $id         ID of the image and caption container element, i.e. `<figure>` or `<div>`.
 *     @type string $caption_id ID of the caption element, i.e. `<figcaption>` or `<p>`.
 *     @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.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if (!empty($output)) {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'caption_id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    $id = '';
    $caption_id = '';
    $describedby = '';
    if ($atts['id']) {
        $atts['id'] = sanitize_html_class($atts['id']);
        $id = 'id="' . esc_attr($atts['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']);
    }
    if ($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']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width.
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = sprintf('<figure %s%s%sclass="%s">%s%s</figure>', $id, $describedby, $style, esc_attr($class), do_shortcode($content), sprintf('<figcaption %sclass="wp-caption-text">%s</figcaption>', $caption_id, $atts['caption']));
    } else {
        $html = sprintf('<div %s%sclass="%s">%s%s</div>', $id, $style, esc_attr($class), str_replace('<img ', '<img ' . $describedby, do_shortcode($content)), sprintf('<p %sclass="wp-caption-text">%s</p>', $caption_id, $atts['caption']));
    }
    return $html;
}

WordPress Version: 5.3

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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', 'caption_id', 'align',
 * 'width', 'caption', and 'class'.
 *
 * @since 2.6.0
 * @since 3.9.0 The `class` attribute was added.
 * @since 5.1.0 The `caption_id` attribute was added.
 *
 * @param array  $attr {
 *     Attributes of the caption shortcode.
 *
 *     @type string $id         ID of the image and caption container element, i.e. `<figure>` or `<div>`.
 *     @type string $caption_id ID of the caption element, i.e. `<figcaption>` or `<p>`.
 *     @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.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if (!empty($output)) {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'caption_id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    $id = '';
    $caption_id = '';
    $describedby = '';
    if ($atts['id']) {
        $atts['id'] = sanitize_html_class($atts['id']);
        $id = 'id="' . esc_attr($atts['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']);
    }
    if ($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']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = sprintf('<figure %s%s%sclass="%s">%s%s</figure>', $id, $describedby, $style, esc_attr($class), do_shortcode($content), sprintf('<figcaption %sclass="wp-caption-text">%s</figcaption>', $caption_id, $atts['caption']));
    } else {
        $html = sprintf('<div %s%sclass="%s">%s%s</div>', $id, $style, esc_attr($class), str_replace('<img ', '<img ' . $describedby, do_shortcode($content)), sprintf('<p %sclass="wp-caption-text">%s</p>', $caption_id, $atts['caption']));
    }
    return $html;
}

WordPress Version: 5.1

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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', 'caption_id', 'align',
 * 'width', 'caption', and 'class'.
 *
 * @since 2.6.0
 * @since 3.9.0 The `class` attribute was added.
 * @since 5.1.0 The `caption_id` attribute was added.
 *
 * @param array  $attr {
 *     Attributes of the caption shortcode.
 *
 *     @type string $id         ID of the image and caption container element, i.e. `<figure>` or `<div>`.
 *     @type string $caption_id ID of the caption element, i.e. `<figcaption>` or `<p>`.
 *     @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.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'caption_id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    $id = $caption_id = $describedby = '';
    if ($atts['id']) {
        $atts['id'] = sanitize_html_class($atts['id']);
        $id = 'id="' . esc_attr($atts['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']);
    }
    if ($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']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = sprintf('<figure %s%s%sclass="%s">%s%s</figure>', $id, $describedby, $style, esc_attr($class), do_shortcode($content), sprintf('<figcaption %sclass="wp-caption-text">%s</figcaption>', $caption_id, $atts['caption']));
    } else {
        $html = sprintf('<div %s%sclass="%s">%s%s</div>', $id, $style, esc_attr($class), str_replace('<img ', '<img ' . $describedby, do_shortcode($content)), sprintf('<p %sclass="wp-caption-text">%s</p>', $caption_id, $atts['caption']));
    }
    return $html;
}

WordPress Version: 9.5

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    } else {
        $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
    }
    return $html;
}

WordPress Version: 9.3

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="max-width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    } else {
        $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
    }
    return $html;
}

WordPress Version: .20

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    } else {
        $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
    }
    return $html;
}

WordPress Version: 9.2

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="max-width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    } else {
        $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
    }
    return $html;
}

WordPress Version: .10

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    } else {
        $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
    }
    return $html;
}

WordPress Version: 4.9

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="max-width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    } else {
        $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
    }
    return $html;
}

WordPress Version: 4.7

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    if ($html5) {
        $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    } else {
        $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
    }
    return $html;
}

WordPress Version: 4.6

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * 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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filters the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filters the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    $html = '';
    if ($html5) {
        $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    } else {
        $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
    }
    return $html;
}

WordPress Version: 4.4

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    $html5 = current_theme_supports('html5', 'caption');
    // HTML5 captions never added the extra 10px to the image width
    $width = $html5 ? $atts['width'] : (10 + $atts['width']);
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $width    Width of the caption in pixels. To remove this inline style,
     *                         return zero.
     * @param array  $atts     Attributes of the caption shortcode.
     * @param string $content  The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    $html = '';
    if ($html5) {
        $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    } else {
        $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
    }
    return $html;
}

WordPress Version: 3.1

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 4.3

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr(sanitize_html_class($atts['id'])) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 2.5

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 2.4

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .30

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 2.3

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .20

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 2.2

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .10

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 4.2

/**
 * Builds the Caption shortcode output.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 1.8

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 1.5

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .40

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 1.4

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .30

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 1.3

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .20

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 1.2

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .10

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 4.1

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 0.8

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 0.4

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .30

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 0.3

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .20

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 0.2

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .10

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 4.0

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 9.9

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 9.2

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .10

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 3.9

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @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.
 * }
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display the caption.
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    /**
     * Filter the default caption shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default caption template.
     *
     * @since 2.6.0
     *
     * @see img_caption_shortcode()
     *
     * @param string $output  The caption output. Default empty.
     * @param array  $attr    Attributes of the caption shortcode.
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', 'class' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $class = trim('wp-caption ' . $atts['align'] . ' ' . $atts['class']);
    if (current_theme_supports('html5', 'caption')) {
        return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr($class) . '">' . do_shortcode($content) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @see img_caption_shortcode()
     *
     * @param int    $caption_width Width of the caption in pixels. To remove this inline style,
     *                              return zero.
     * @param array  $atts          Attributes of the caption shortcode.
     * @param string $content       The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="' . esc_attr($class) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 8.4

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .30

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 8.3

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .20

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 8.2

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .11

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 7.5

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .40

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 7.4

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .30

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 7.3

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .20

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 7.2

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: .11

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    } elseif (strpos($attr['caption'], '<') !== false) {
        $attr['caption'] = wp_kses($attr['caption'], 'post');
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

WordPress Version: 3.7

/**
 * The Caption shortcode.
 *
 * Allows a plugin to replace the content that would otherwise be returned. The
 * filter is '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'.
 *
 * @since 2.6.0
 *
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
 */
function img_caption_shortcode($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    // Allow plugins/themes to override the default caption template.
    $output = apply_filters('img_caption_shortcode', '', $attr, $content);
    if ($output != '') {
        return $output;
    }
    $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr, 'caption');
    $atts['width'] = (int) $atts['width'];
    if ($atts['width'] < 1 || empty($atts['caption'])) {
        return $content;
    }
    if (!empty($atts['id'])) {
        $atts['id'] = 'id="' . esc_attr($atts['id']) . '" ';
    }
    $caption_width = 10 + $atts['width'];
    /**
     * Filter the width of an image's caption.
     *
     * By default, the caption is 10 pixels greater than the width of the image,
     * to prevent post content from running up against a floated image.
     *
     * @since 3.7.0
     *
     * @param int $caption_width Width in pixels. To remove this inline style, return zero.
     * @param array $atts {
     *     The attributes of the caption shortcode.
     *
     *     @type string 'id'      The ID of the div element for the caption.
     *     @type string 'align'   The class name that aligns the caption. Default 'alignnone'.
     *     @type int    'width'   The width of the image being captioned.
     *     @type string 'caption' The image's caption.
     * }
     * @param string $content The image element, possibly wrapped in a hyperlink.
     */
    $caption_width = apply_filters('img_caption_shortcode_width', $caption_width, $atts, $content);
    $style = '';
    if ($caption_width) {
        $style = 'style="width: ' . (int) $caption_width . 'px" ';
    }
    return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr($atts['align']) . '">' . do_shortcode($content) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}