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
This commit is contained in:
Scott Taylor 2014-07-16 22:04:08 +00:00
parent 722930611c
commit 17d67d93e7
2 changed files with 17 additions and 1 deletions

View File

@ -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;

View File

@ -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' );
}
}