WordPress.org

Make WordPress Core

Ticket #34722: 34722.diff

File 34722.diff, 1.8 KB (added by MattyRob, 3 years ago)
  • wp-includes/formatting.php

     
    474474        // Add a double line break below block-level closing tags.
    475475        $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
    476476
     477        // Add a double line break above and below Shortcode opening tags.
     478        global $shortcode_tags;
     479        $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
     480        $pee = preg_replace( '!(\[(\[?)(' . $tagregexp . ')\](\]?))!', "\n\n$1\n\n", $pee );
     481
     482        // Add a double line break above and below Shortcode closing tags.
     483        $pee = preg_replace( '!((\[?)\[\/(' . $tagregexp . ')\](\]?))!', "\n\n$1\n\n", $pee );
     484
    477485        // Standardize newline characters to "\n".
    478486        $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
    479487
     
    523531        // Under certain strange conditions it could create a P of entirely whitespace.
    524532        $pee = preg_replace('|<p>\s*</p>|', '', $pee);
    525533
     534        // Remove <p> tags and line breaks around shortcodes
     535        $pee = preg_replace( '!\n<p>(\[(\[?)(' . $tagregexp . ')\](\]?))</p>\n!', "$1", $pee );
     536        $pee = preg_replace( '!\n<p>((\[?)\[\/(' . $tagregexp . ')\](\]?))</p>\n!', "$1", $pee );
     537
    526538        // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    527539        $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);
    528540
     
    538550
    539551        // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    540552        $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
    541 
    542553        // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    543554        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
    544555