Make WordPress Core

Ticket #37183: 37183.patch

File 37183.patch, 2.0 KB (added by pputzer, 7 years ago)

New img_caption_shortcode_content filter

  • package.json

     
    1010  "license": "GPL-2.0+",
    1111  "devDependencies": {
    1212    "autoprefixer": "~6.3.3",
    13     "grunt": "~0.4.5",
     13    "grunt": "^0.4.5",
    1414    "grunt-browserify": "~5.0.0",
    1515    "grunt-contrib-clean": "~1.0.0",
    1616    "grunt-contrib-compress": "~1.1.0",
  • src/wp-includes/media.php

     
    14581458function img_caption_shortcode( $attr, $content = null ) {
    14591459        // New-style shortcode with the caption inside the shortcode with the link and image tags.
    14601460        if ( ! isset( $attr['caption'] ) ) {
    1461                 if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
     1461                $matches = array();
     1462                $regex = '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is';
     1463                preg_match( $regex, $content, $matches );
     1464
     1465                /**
     1466                 * Filter the content and caption for use in the caption shortcode.
     1467                 *
     1468                 * If the filtered array `$matches` is empty, an old-style caption attribute
     1469                 * will be assumed.
     1470                 *
     1471                 * @since x.x.x
     1472                 *
     1473                 * @param array $matches        The default result of `preg_match`.
     1474                 * @param string $content       The content included in the caption shortcode (including the image).
     1475                 * @param string $regex         The regular expression capturing the image and the caption attribute.
     1476                 *
     1477                 * @return array $matches {
     1478                 *              Array corresponding to the result of `preg_match`.
     1479                 *
     1480                 *              @type string 1  The new `$content` used in the shortcode (i.e. the `<img>` tag).
     1481                 *              @type string 2  The caption (set as `$attr['caption']`.
     1482                 * }
     1483                 */
     1484                $matches = apply_filters( 'img_caption_shortcode_content', $matches, $content, $regex );
     1485
     1486                if ( ! empty ( $matches ) ) {
    14621487                        $content = $matches[1];
    14631488                        $attr['caption'] = trim( $matches[2] );
    14641489                }