Ticket #19968: 19968.diff

File 19968.diff, 3.3 KB (added by GaryJ, 16 months ago)

Named groups defined for get_shortcode_regex(), used in do_shortcode_tags() and strip_shortcode_tag()

  • shortcodes.php

     
    179179        // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() 
    180180        return 
    181181                  '\\['                              // Opening bracket 
    182                 . '(\\[?)'                           // 1: Optional second opening bracket for escaping shortcodes: [[tag]] 
    183                 . "($tagregexp)"                     // 2: Shortcode name 
     182                . '(?P<escape-open>\\[?)'            // 1: Optional second opening bracket for escaping shortcodes: [[tag]] 
     183                . "(?P<name>$tagregexp)"             // 2: Shortcode name 
    184184                . '\\b'                              // Word boundary 
    185                 . '('                                // 3: Unroll the loop: Inside the opening shortcode tag 
     185                . '(?P<attributes>'                  // 3: Unroll the loop: Inside the opening shortcode tag 
    186186                .     '[^\\]\\/]*'                   // Not a closing bracket or forward slash 
    187187                .     '(?:' 
    188188                .         '\\/(?!\\])'               // A forward slash not followed by a closing bracket 
     
    195195                . '|' 
    196196                .     '\\]'                          // Closing bracket 
    197197                .     '(?:' 
    198                 .         '('                        // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags 
     198                .         '(?P<content>'             // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags 
    199199                .             '[^\\[]*+'             // Not an opening bracket 
    200200                .             '(?:' 
    201201                .                 '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag 
     
    205205                .         '\\[\\/\\2\\]'             // Closing shortcode tag 
    206206                .     ')?' 
    207207                . ')' 
    208                 . '(\\]?)';                          // 6: Optional second closing brocket for escaping shortcodes: [[tag]] 
     208                . '(?P<escape-close>\\]?)';          // 6: Optional second closing bracket for escaping shortcodes: [[tag]] 
    209209} 
    210210 
    211211/** 
     
    223223        global $shortcode_tags; 
    224224 
    225225        // allow [[foo]] syntax for escaping a tag 
    226         if ( $m[1] == '[' && $m[6] == ']' ) { 
     226        if ( $m['escape-open'] == '[' && $m['escape-close'] == ']' ) { 
    227227                return substr($m[0], 1, -1); 
    228228        } 
    229229 
    230         $tag = $m[2]; 
    231         $attr = shortcode_parse_atts( $m[3] ); 
     230        $tag = $m['name']; 
     231        $attr = shortcode_parse_atts( $m['attributes'] ); 
    232232 
    233         if ( isset( $m[5] ) ) { 
     233        if ( isset( $m['content'] ) ) { 
    234234                // enclosing tag - extra parameter 
    235                 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6]; 
     235                return $m['escape-open'] . call_user_func( $shortcode_tags[$tag], $attr, $m['content'], $tag ) . $m['escape-close']; 
    236236        } else { 
    237237                // self-closing tag 
    238                 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, NULL,  $tag ) . $m[6]; 
     238                return $m['escape-open'] . call_user_func( $shortcode_tags[$tag], $attr, NULL,  $tag ) . $m['escape-close']; 
    239239        } 
    240240} 
    241241 
     
    324324 
    325325function strip_shortcode_tag( $m ) { 
    326326        // allow [[foo]] syntax for escaping a tag 
    327         if ( $m[1] == '[' && $m[6] == ']' ) { 
     327        if ( $m['escape-open'] == '[' && $m['escape-close'] == ']' ) { 
    328328                return substr($m[0], 1, -1); 
    329329        } 
    330330 
    331         return $m[1] . $m[6]; 
     331        return $m['escape-open'] . $m['escape-close']; 
    332332} 
    333333 
    334334add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()