From 9df4077f95a1f21aaf5b3a2a0e0dabd10bd9c716 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Wed, 16 Apr 2008 21:07:04 +0000 Subject: [PATCH] Allow shortcodes to run before or after wpautop()/texturize() formatting. Default to before for WP 2.5 compat. Props AaronCampbell git-svn-id: http://svn.automattic.com/wordpress/trunk@7699 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 4 +++- wp-includes/media.php | 10 ++++---- wp-includes/shortcodes.php | 48 ++++++++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index a27101886..3446671fe 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -26,7 +26,7 @@ function wptexturize($text) { 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 @@ function wpautop($pee, $br = 1) { $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*?(]*>)!', "

$1

$2", $pee); $pee = preg_replace( '|

|', "$1

", $pee ); $pee = preg_replace('!

\s*(]*>)\s*

!', "$1", $pee); // don't pee all over a tag @@ -840,6 +841,7 @@ function wp_trim_excerpt($text) { // Fakes an excerpt if needed $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); + $text = preg_replace('|//\s*'; } - + return $html; } -add_shortcode('gallery', 'gallery_shortcode'); +add_shortcode('gallery', 'gallery_shortcode', true); function gallery_shortcode($attr) { global $post; @@ -376,7 +376,7 @@ function gallery_shortcode($attr) { $captiontag = tag_escape($captiontag); $columns = intval($columns); $itemwidth = $columns > 0 ? floor(100/$columns) : 100; - + $output = apply_filters('gallery_style', "