Index: trunk/wp-includes/shortcodes.php =================================================================== --- trunk/wp-includes/shortcodes.php (revision 7587) +++ trunk/wp-includes/shortcodes.php (working copy) @@ -47,17 +47,18 @@ $shortcode_tags = array(); -function add_shortcode($tag, $func) { +function add_shortcode($tag, $func, $post_formatting = false) { global $shortcode_tags; - if ( is_callable($func) ) - $shortcode_tags[$tag] = $func; + if ( is_callable($func) ) { + $shortcode_tags[($post_formatting)? 11:9][$tag] = $func; + } } function remove_shortcode($tag) { global $shortcode_tags; - unset($shortcode_tags[$tag]); + unset($shortcode_tags[9][$tag], $shortcode_tags[11][$tag]); } function remove_all_shortcodes() { @@ -66,21 +67,37 @@ $shortcode_tags = array(); } -function do_shortcode($content) { +function do_shortcode_post_formatting($content) { + return do_shortcode($content, true); +} +function do_shortcode($content, $post_formatting = false) { + $pattern = get_shortcode_regex($post_formatting); + if (!$pattern) { + return $content; + } else { + $callback_func = 'do_shortcode_tag'; + if ($post_formatting) + $callback_func .= '_post_formatting'; + + return preg_replace_callback('/' . $pattern . '/s', $callback_func, $content); + } +} +function get_shortcode_regex($post_formatting) { global $shortcode_tags; - if (empty($shortcode_tags) || !is_array($shortcode_tags)) - return $content; + if (empty($shortcode_tags[($post_formatting)? 11:9]) || !is_array($shortcode_tags[($post_formatting)? 11:9])) + return false; - $tagnames = array_keys($shortcode_tags); + $tagnames = array_keys($shortcode_tags[($post_formatting)? 11:9]); $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); - $pattern = '/\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/s'; + return '\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?'; +} - return preg_replace_callback($pattern, 'do_shortcode_tag', $content); +function do_shortcode_tag_post_formatting($m) { + return do_shortcode_tag($m, true); } - -function do_shortcode_tag($m) { +function do_shortcode_tag($m, $post_formatting = false) { global $shortcode_tags; $tag = $m[1]; @@ -88,10 +105,10 @@ if ( isset($m[4]) ) { // enclosing tag - extra parameter - return call_user_func($shortcode_tags[$tag], $attr, $m[4]); + return call_user_func($shortcode_tags[($post_formatting)? 11:9][$tag], $attr, $m[4]); } else { // self-closing tag - return call_user_func($shortcode_tags[$tag], $attr); + return call_user_func($shortcode_tags[($post_formatting)? 11:9][$tag], $attr); } } @@ -129,6 +146,7 @@ return $out; } -add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop() +add_filter( 'the_content', 'do_shortcode', 9 ); +add_filter( 'the_content', 'do_shortcode_post_formatting', 11 ); ?> Index: trunk/wp-includes/formatting.php =================================================================== --- trunk/wp-includes/formatting.php (revision 7587) +++ trunk/wp-includes/formatting.php (working copy) @@ -26,7 +26,7 @@ for ( $i = 0; $i < $stop; $i++ ) { $curl = $textarr[$i]; - if (isset($curl{0}) && '<' != $curl{0} && '[' != $curl{0} && $next) { // If it's not a tag + if (isset($curl{0}) && '<' != $curl{0} && '[' != $curl{0} && $next) { // If it's not a tag or shortcode // static strings $curl = str_replace($static_characters, $static_replacements, $curl); // regular expressions @@ -74,6 +74,7 @@ $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "
$1
\n", $pee); // make paragraphs, including one at the end $pee = preg_replace('|\s*?
|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace + $pee = preg_replace('/(\s*?' . get_shortcode_regex(true) . '\s*)<\/p>/s', '$1', $pee); // don't auto-p wrap post-formatting shortcodes $pee = preg_replace('!
([^<]+)\s*?((?:div|address|form)[^>]*>)!', "
$1
$2", $pee); $pee = preg_replace( '||', "$1
", $pee ); $pee = preg_replace('!
\s*(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee); // don't pee all over a tag