Make WordPress Core

Ticket #11257: ticket-11257-v3.patch

File ticket-11257-v3.patch, 2.8 KB (added by miqrogroove, 14 years ago)

Alternative patch design with changes suggested by azaozz.

  • formatting.php

     
    173173 * or 'false'.
    174174 *
    175175 * @since 0.71
     176 * @uses $shortcode_tags
    176177 *
    177178 * @param string $pee The text which has to be formatted.
    178179 * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
    179180 * @return string Text which has been converted into correct paragraph tags.
    180181 */
    181182function wpautop($pee, $br = 1) {
     183        global $shortcode_tags;
     184
    182185        if ( trim($pee) === '' )
    183186                return '';
    184187        $pee = $pee . "\n"; // just to make things a little easier, pad the end
     
    216219        if (strpos($pee, '<pre') !== false)
    217220                $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
    218221        $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
    219         $pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone
    220222
     223        // don't auto-p wrap shortcodes that stand alone
     224        $tagnames = array_keys($shortcode_tags);
     225        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
     226        $pee = preg_replace('/<p>\\s*?(.?\\[('.$tagregexp.')\\b.*?\\/?\\](?:.+?\\[\\/\\2\\])?.?)\\s*<\\/p>/s', '$1', $pee);
     227
    221228        return $pee;
    222229}
    223230
  • shortcodes.php

     
    176176        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    177177
    178178        // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes()
    179         return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
     179        return '(.?)\\[('.$tagregexp.')\\b(.*?)\\/?\\](?:(.+?)\\[\\/\\2\\])?(.?)';
    180180}
    181181
    182182/**
     
    194194        global $shortcode_tags;
    195195
    196196        // allow [[foo]] syntax for escaping a tag
    197         if ($m[1] == '[' && $m[6] == ']') {
     197        if ($m[1] == '[' && $m[5] == ']') {
    198198                return substr($m[0], 1, -1);
    199199        }
    200200
    201201        $tag = $m[2];
    202202        $attr = shortcode_parse_atts($m[3]);
    203203
    204         if ( isset($m[5]) ) {
     204        if ( isset($m[4]) ) {
    205205                // enclosing tag - extra parameter
    206                 return $m[1] . call_user_func($shortcode_tags[$tag], $attr, $m[5], $m[2]) . $m[6];
     206                return $m[1] . call_user_func($shortcode_tags[$tag], $attr, $m[4], $m[2]) . $m[5];
    207207        } else {
    208208                // self-closing tag
    209                 return $m[1] . call_user_func($shortcode_tags[$tag], $attr, NULL, $m[2]) . $m[6];
     209                return $m[1] . call_user_func($shortcode_tags[$tag], $attr, NULL, $m[2]) . $m[5];
    210210        }
    211211}
    212212
     
    290290
    291291        $pattern = get_shortcode_regex();
    292292
    293         return preg_replace('/'.$pattern.'/s', '$1$6', $content);
     293        return preg_replace('/'.$pattern.'/s', '$1$5', $content);
    294294}
    295295
    296296add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()
    297297
    298 ?>
    299  No newline at end of file
     298?>