From 570cb5374c4ced31f5228e614a52bf4f2dca5b2e Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 5 Jun 2008 20:11:38 +0000 Subject: [PATCH] Strip shortcodes when making excerpts. Props hailin. fixes #7100 git-svn-id: http://svn.automattic.com/wordpress/trunk@8054 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 3 +++ wp-includes/shortcodes.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 052445d187..4bc9460d2a 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -839,6 +839,9 @@ function human_time_diff( $from, $to = '' ) { function wp_trim_excerpt($text) { // Fakes an excerpt if needed if ( '' == $text ) { $text = get_the_content(''); + + $text = strip_shortcodes( $text ); + $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); diff --git a/wp-includes/shortcodes.php b/wp-includes/shortcodes.php index 907f7ff30a..490f7a6826 100644 --- a/wp-includes/shortcodes.php +++ b/wp-includes/shortcodes.php @@ -134,6 +134,23 @@ function shortcode_atts($pairs, $atts) { return $out; } +/* + * stip all the shortcodes from a post's content + * returns the content without shortcodes + */ +function strip_shortcodes( $content ) { + + global $shortcode_tags; + + if (empty($shortcode_tags) || !is_array($shortcode_tags)) + return $content; + + $pattern = get_shortcode_regex(); + + return preg_replace('/'.$pattern.'/s', '', $content); + +} + add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop() ?>