From 17d67d93e712a9c8710a9a2758fe3d888e07ed16 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 16 Jul 2014 22:04:08 +0000 Subject: [PATCH] Make `has_shortcode()` recursive/work for nested shortcodes. Adds unit test. Props katzwebdesign. Fixes #26343. git-svn-id: https://develop.svn.wordpress.org/trunk@29197 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/shortcodes.php | 5 ++++- tests/phpunit/tests/shortcode.php | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/shortcodes.php b/src/wp-includes/shortcodes.php index 47cb57a9b2..fc850460f2 100644 --- a/src/wp-includes/shortcodes.php +++ b/src/wp-includes/shortcodes.php @@ -165,8 +165,11 @@ function has_shortcode( $content, $tag ) { return false; foreach ( $matches as $shortcode ) { - if ( $tag === $shortcode[2] ) + if ( $tag === $shortcode[2] ) { return true; + } elseif ( isset( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag ) ) { + return has_shortcode( $shortcode[5], $tag ); + } } } return false; diff --git a/tests/phpunit/tests/shortcode.php b/tests/phpunit/tests/shortcode.php index 79f21cb5cd..7e8b97188a 100644 --- a/tests/phpunit/tests/shortcode.php +++ b/tests/phpunit/tests/shortcode.php @@ -394,4 +394,17 @@ EOF; $this->assertEquals( $output, shortcode_unautop( $in ) ); } } + + /** + * @ticket 26343 + */ + function test_has_shortcode() { + $content = 'This is a blob with [gallery] in it'; + $this->assertTrue( has_shortcode( $content, 'gallery' ) ); + + add_shortcode( 'foo', '__return_false' ); + $content_nested = 'This is a blob with [foo] [gallery] [/foo] in it'; + $this->assertTrue( has_shortcode( $content_nested, 'gallery' ) ); + remove_shortcode( 'foo' ); + } }