diff --git src/wp-includes/shortcodes.php src/wp-includes/shortcodes.php
index 47cb57a..3b929fa 100644
|
|
function shortcode_exists( $tag ) { |
150 | 150 | * |
151 | 151 | * @since 3.6.0 |
152 | 152 | * |
153 | | * @global array $shortcode_tags |
154 | | * @param string $tag |
155 | | * @return boolean |
| 153 | * @param string $content Content in which to find shortcode |
| 154 | * @param string $tag Shortcode tag to find |
| 155 | * @param bool $recursive Whether to search recursively in other shortcode's content as well |
| 156 | * @return bool Whether the shorcode tag was found in the content |
156 | 157 | */ |
157 | | function has_shortcode( $content, $tag ) { |
| 158 | function has_shortcode( $content, $tag, $recursive = false ) { |
158 | 159 | if ( false === strpos( $content, '[' ) ) { |
159 | 160 | return false; |
160 | 161 | } |
161 | 162 | |
162 | 163 | if ( shortcode_exists( $tag ) ) { |
163 | 164 | preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ); |
164 | | if ( empty( $matches ) ) |
| 165 | |
| 166 | if ( empty( $matches ) ) { |
165 | 167 | return false; |
| 168 | } |
166 | 169 | |
167 | 170 | foreach ( $matches as $shortcode ) { |
168 | | if ( $tag === $shortcode[2] ) |
| 171 | if ( $tag === $shortcode[2] ) { |
| 172 | // Shortcode matches in current content |
| 173 | return true; |
| 174 | } |
| 175 | else if ( $recursive && ! empty( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag, true ) ) { |
| 176 | // Shortcode recursively matched inside the content of one of the shortcodes in the content |
169 | 177 | return true; |
| 178 | } |
170 | 179 | } |
171 | 180 | } |
172 | 181 | return false; |
diff --git tests/phpunit/tests/shortcode.php tests/phpunit/tests/shortcode.php
index 79f21cb..2f63a16 100644
|
|
EOF; |
394 | 394 | $this->assertEquals( $output, shortcode_unautop( $in ) ); |
395 | 395 | } |
396 | 396 | } |
| 397 | |
| 398 | /** |
| 399 | * @ticket 26343 |
| 400 | */ |
| 401 | function test_has_shortcode() { |
| 402 | add_shortcode( 'foo', '__return_false' ); |
| 403 | add_shortcode( 'bar', '__return_false' ); |
| 404 | add_shortcode( 'baz', '__return_false' ); |
| 405 | |
| 406 | $content = 'Sample shortcodes [foo] and nested [bar] shortcode [baz] testing [/bar].'; |
| 407 | $this->assertTrue( has_shortcode( $content, 'foo' ) ); |
| 408 | $this->assertTrue( has_shortcode( $content, 'foo', true ) ); |
| 409 | $this->assertTrue( has_shortcode( $content, 'bar' ) ); |
| 410 | $this->assertTrue( has_shortcode( $content, 'bar', true ) ); |
| 411 | $this->assertFalse( has_shortcode( $content, 'baz' ) ); |
| 412 | $this->assertTrue( has_shortcode( $content, 'baz', true ) ); |
| 413 | |
| 414 | remove_shortcode( 'foo' ); |
| 415 | remove_shortcode( 'bar' ); |
| 416 | remove_shortcode( 'baz' ); |
| 417 | } |
| 418 | |
397 | 419 | } |