Make WordPress Core


Ignore:
Timestamp:
12/01/2009 07:46:36 AM (14 years ago)
Author:
azaozz
Message:

Separate the removal of <p> wrapping from shortcodes into another function and apply it with different filter, props miqrogroove, props mdawaffe, see #11257, see #11249

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r12275 r12302  
    180180 */
    181181function wpautop($pee, $br = 1) {
     182
    182183    if ( trim($pee) === '' )
    183184        return '';
     
    217218        $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
    218219    $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
     220
     221    return $pee;
     222}
     223
     224/**
     225 * Don't auto-p wrap shortcodes that stand alone
     226 *
     227 * Ensures that shortcodes are not wrapped in <<p>>...<</p>>.
     228 *
     229 * @since 2.9.0
     230 *
     231 * @param string $pee The content.
     232 * @return string The filtered content.
     233 */
     234function shortcode_unautop($pee) {
     235    global $shortcode_tags;
     236
     237    if ( !empty($shortcode_tags) && is_array($shortcode_tags) ) {
     238        $tagnames = array_keys($shortcode_tags);
     239        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
     240        $pee = preg_replace('/<p>\\s*?(\\[(' . $tagregexp . ')\\b.*?\\/?\\](?:.+?\\[\\/\\2\\])?)\\s*<\\/p>/s', '$1', $pee);
     241    }
    220242
    221243    return $pee;
Note: See TracChangeset for help on using the changeset viewer.