WordPress.org

Make WordPress Core

Ticket #6444: 6444.autop.001.diff

File 6444.autop.001.diff, 2.0 KB (added by markjaquith, 14 years ago)
  • wp-includes/shortcodes.php

     
    6767}
    6868
    6969function do_shortcode($content) {
     70        $pattern = get_shortcode_regex();
     71        if ( !$pattern )
     72                return $content;
     73        else
     74                return preg_replace_callback('/' . $pattern . '/s', 'do_shortcode_tag', $content);
     75}
     76
     77// Note: this returns a partial regex for integration into a larger regex. Your final regex should use "/" as delimiters and use the "s" switch
     78function get_shortcode_regex() {
    7079        global $shortcode_tags;
    7180
    7281        if (empty($shortcode_tags) || !is_array($shortcode_tags))
    73                 return $content;
     82                return false;
    7483
    7584        $tagnames = array_keys($shortcode_tags);
     85
    7686        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    77 
    78         $pattern = '/\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/s';
    79 
    80         return preg_replace_callback($pattern, 'do_shortcode_tag', $content);
     87        return '\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?';
    8188}
    8289
    8390function 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 block-level 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