Make WordPress Core

Ticket #15600: 15600.2.diff

File 15600.2.diff, 5.1 KB (added by mdawaffe, 12 years ago)
  • wp-includes/shortcodes.php

     
    148148                return $content;
    149149
    150150        $pattern = get_shortcode_regex();
    151         return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content);
     151        return preg_replace_callback( "/$pattern/sx", 'do_shortcode_tag', $content );
    152152}
    153153
    154154/**
     
    174174        global $shortcode_tags;
    175175        $tagnames = array_keys($shortcode_tags);
    176176        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    177 
    178         // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes()
    179         return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
     177        // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
     178        return "
     179                \\[                                    # Opening bracket
     180                (\\[?)                                 # 1: Optional second opening bracket for escaping shortcodes: [[tag]]
     181                ( $tagregexp )                         # 2: Shortcode name
     182                \\b                                    # Word boundary
     183                (                                      # 3: Unroll the loop: Inside the opening shortcode tag
     184                        [^\\]'\"]*                     # Not a closing bracket, single or double quote
     185                        (?:
     186                                (?:\"[^\"]*\"|'[^']*') # Anything in quotes
     187                                [^\\]'\"]*             # Not a closing bracket, single or double quote
     188                        )*
     189                )
     190                (\\/?)                                 # 4: Self closing?
     191                (?(4)                                  # If self closing, then ...
     192                        \\]                            # ... Closing bracket
     193                        |                              # Else ...
     194                        (?:
     195                                (.+?)                  # 5: ... Anything between the opening and closing shortcode tags
     196                                \\[\\/\\2\\]           # ... Closing shortcode tag
     197                        )?
     198                )
     199                (.?)                                   # 6: Trailing character
     200        ";
    180201}
    181202
    182203/**
     
    203224
    204225        if ( isset( $m[5] ) ) {
    205226                // enclosing tag - extra parameter
    206                 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6];
     227                return call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6];
    207228        } else {
    208229                // self-closing tag
    209                 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, NULL,  $tag ) . $m[6];
     230                return call_user_func( $shortcode_tags[$tag], $attr, NULL,  $tag ) . $m[6];
    210231        }
    211232}
    212233
     
    290311
    291312        $pattern = get_shortcode_regex();
    292313
    293         return preg_replace('/'.$pattern.'/s', '$1$6', $content);
     314        return preg_replace_callback( "/$pattern/sx", 'strip_shortcode_tag', $content );
    294315}
    295316
     317function strip_shortcode_tag( $m ) {
     318        // allow [[foo]] syntax for escaping a tag
     319        if ( $m[1] == '[' && $m[6] == ']' ) {
     320                return substr($m[0], 1, -1);
     321        }
     322
     323        return $m[6];
     324}
     325
    296326add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()
    297327
    298 ?>
    299  No newline at end of file
     328?>
  • wp-includes/formatting.php

     
    232232 * @param string $pee The content.
    233233 * @return string The filtered content.
    234234 */
    235 function shortcode_unautop($pee) {
     235function shortcode_unautop( $pee ) {
    236236        global $shortcode_tags;
    237237
    238         if ( !empty($shortcode_tags) && is_array($shortcode_tags) ) {
    239                 $tagnames = array_keys($shortcode_tags);
    240                 $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    241                 $pee = preg_replace('/<p>\\s*?(\\[(' . $tagregexp . ')\\b.*?\\/?\\](?:.+?\\[\\/\\2\\])?)\\s*<\\/p>/s', '$1', $pee);
     238        if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) {
     239                return $pee;
    242240        }
    243241
    244         return $pee;
     242        $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
     243
     244        $pattern = "/
     245                <p>                                            # Opening paragraph
     246                \\s*?                                          # Optional leading whitespace
     247                (                                              # 1: The shortcode
     248                        \\[                                    # Opening bracket
     249                        (?: $tagregexp )                       # Shortcode name
     250                        \\b                                    # Word boundary
     251                        (?:                                    # Unroll the loop: Inside the opening shortcode tag
     252                                [^\\]'\"]*                     # Not a closing bracket, single or double quote
     253                                (?:
     254                                        (?:\"[^\"]*\"|'[^']*') # Anything in quotes
     255                                        [^\\]'\"]*             # Not a closing bracket, single or double quote
     256                                )*
     257                        )
     258                        (\\/?)                                 # 2: Self closing?
     259                        (?(2)                                  # If self closing, then ...
     260                                \\]                            # ... Closing bracket
     261                                |                              # Else ...
     262                                (?:
     263                                        .+?                    # ... Anything between the opening and closing shortcode tags
     264                                        \\[\\/\\2\\]           # ... Closing shortcode tag
     265                                )
     266                        )?
     267                )
     268                \\s*                                           # optional trailing whitespace
     269                <\\/p>                                         # closing paragraph
     270        /sx";
     271
     272        return preg_replace( $pattern, '$1', $pee );
    245273}
    246274
    247275/**