WordPress.org

Make WordPress Core

Ticket #6444: 6444-no-p-wrap-shortcodes-r7811-2.patch

File 6444-no-p-wrap-shortcodes-r7811-2.patch, 2.2 KB (added by tellyworth, 13 years ago)

as per the last but with br's stripped too

  • wp-includes/shortcodes.php

     
    7272        if (empty($shortcode_tags) || !is_array($shortcode_tags))
    7373                return $content;
    7474
     75        $pattern = get_shortcode_regex();
     76        return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content);
     77}
     78
     79function get_shortcode_regex() {
     80        global $shortcode_tags;
    7581        $tagnames = array_keys($shortcode_tags);
    7682        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    7783
    78         $pattern = '/\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/s';
    79 
    80         return preg_replace_callback($pattern, 'do_shortcode_tag', $content);
     84        return '\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?';
    8185}
    8286
    8387function do_shortcode_tag($m) {
  • wp-includes/formatting.php

     
    7474        $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
    7575        $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end
    7676        $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
     77        $pee = preg_replace('/<p>(\s*?' . get_shortcode_regex() . '\s*)<\/p>/s', '$1', $pee); // don't auto-p wrap post-formatting shortcodes   
    7778        $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee);
    7879        $pee = preg_replace( '|<p>|', "$1<p>", $pee );
    7980        $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
     
    8788                $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
    8889                $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    8990        }
     91        $pee = preg_replace('/(' . get_shortcode_regex() . ')<br \/>/s', '$1', $pee); // don't br block shortcodes
    9092        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
    9193        $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
    9294        if (strpos($pee, '<pre') !== false)