From ca6bd9ebd55c83a8f23237d995fbc3ff84865178 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Fri, 25 Apr 2008 00:45:31 +0000 Subject: [PATCH] Don't wpautop()-wrap shortcodes that stand alone. fixes #6444 for trunk git-svn-id: http://svn.automattic.com/wordpress/trunk@7815 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 1 + wp-includes/shortcodes.php | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index a27101886..052445d18 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -92,6 +92,7 @@ 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; } diff --git a/wp-includes/shortcodes.php b/wp-includes/shortcodes.php index 7803b3c52..907f7ff30 100644 --- a/wp-includes/shortcodes.php +++ b/wp-includes/shortcodes.php @@ -72,12 +72,16 @@ function do_shortcode($content) { if (empty($shortcode_tags) || !is_array($shortcode_tags)) return $content; + $pattern = get_shortcode_regex(); + return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content); +} + +function get_shortcode_regex() { + global $shortcode_tags; $tagnames = array_keys($shortcode_tags); $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); - $pattern = '/\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/s'; - - return preg_replace_callback($pattern, 'do_shortcode_tag', $content); + return '\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?'; } function do_shortcode_tag($m) {