From 31bc813a6d766251f982be9834f46d87a57d8a3b Mon Sep 17 00:00:00 2001 From: azaozz Date: Tue, 1 Dec 2009 07:46:36 +0000 Subject: [PATCH] Separate the removal of

wrapping from shortcodes into another function and apply it with different filter, props miqrogroove, props mdawaffe, see #11257, see #11249 git-svn-id: http://svn.automattic.com/wordpress/trunk@12302 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-filters.php | 19 +++++++++++-------- wp-includes/formatting.php | 24 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 94a95c858..5f6a32deb 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -88,9 +88,10 @@ foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', // Format text area for display. foreach ( array( 'term_description' ) as $filter ) { - add_filter( $filter, 'wptexturize' ); - add_filter( $filter, 'convert_chars' ); - add_filter( $filter, 'wpautop' ); + add_filter( $filter, 'wptexturize' ); + add_filter( $filter, 'convert_chars' ); + add_filter( $filter, 'wpautop' ); + add_filter( $filter, 'shortcode_unautop'); } // Format for RSS @@ -107,13 +108,15 @@ add_filter( 'the_content', 'wptexturize' ); add_filter( 'the_content', 'convert_smilies' ); add_filter( 'the_content', 'convert_chars' ); add_filter( 'the_content', 'wpautop' ); +add_filter( 'the_content', 'shortcode_unautop' ); add_filter( 'the_content', 'prepend_attachment' ); -add_filter( 'the_excerpt', 'wptexturize' ); -add_filter( 'the_excerpt', 'convert_smilies' ); -add_filter( 'the_excerpt', 'convert_chars' ); -add_filter( 'the_excerpt', 'wpautop' ); -add_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); +add_filter( 'the_excerpt', 'wptexturize' ); +add_filter( 'the_excerpt', 'convert_smilies' ); +add_filter( 'the_excerpt', 'convert_chars' ); +add_filter( 'the_excerpt', 'wpautop' ); +add_filter( 'the_excerpt', 'shortcode_unautop'); +add_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); add_filter( 'comment_text', 'wptexturize' ); add_filter( 'comment_text', 'convert_chars' ); diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index afcc6d773..85fb579e1 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -179,6 +179,7 @@ function clean_pre($matches) { * @return string Text which has been converted into correct paragraph tags. */ function wpautop($pee, $br = 1) { + if ( trim($pee) === '' ) return ''; $pee = $pee . "\n"; // just to make things a little easier, pad the end @@ -216,7 +217,28 @@ function wpautop($pee, $br = 1) { if (strpos($pee, ']*>)(.*?)!is', 'clean_pre', $pee ); $pee = preg_replace( "|\n

$|", '

', $pee ); - $pee = preg_replace('/

\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone + + return $pee; +} + +/** + * Don't auto-p wrap shortcodes that stand alone + * + * Ensures that shortcodes are not wrapped in <

>...<

>. + * + * @since 2.9.0 + * + * @param string $pee The content. + * @return string The filtered content. + */ +function shortcode_unautop($pee) { + global $shortcode_tags; + + if ( !empty($shortcode_tags) && is_array($shortcode_tags) ) { + $tagnames = array_keys($shortcode_tags); + $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); + $pee = preg_replace('/

\\s*?(\\[(' . $tagregexp . ')\\b.*?\\/?\\](?:.+?\\[\\/\\2\\])?)\\s*<\\/p>/s', '$1', $pee); + } return $pee; }