diff --git src/wp-includes/shortcodes.php src/wp-includes/shortcodes.php
index c6df28b..565207e 100644
|
|
function shortcode_exists( $tag ) { |
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | | * Whether the passed content contains the specified shortcode |
| 130 | * Whether the passed content contains any or specified shortcode. |
131 | 131 | * |
132 | 132 | * @since 3.6.0 |
133 | 133 | * |
134 | 134 | * @global array $shortcode_tags |
135 | 135 | * |
136 | 136 | * @param string $content Content to search for shortcodes. |
137 | | * @param string $tag Shortcode tag to check. |
138 | | * @return bool Whether the passed content contains the given shortcode. |
| 137 | * @param string $tag Shortcode tag to check. Default Empty string. |
| 138 | * @return bool $return Whether the passed content contains any or specified shortcode. |
139 | 139 | */ |
140 | | function has_shortcode( $content, $tag ) { |
| 140 | function has_shortcode( $content, $tag = '' ) { |
141 | 141 | if ( false === strpos( $content, '[' ) ) { |
142 | 142 | return false; |
143 | 143 | } |
| 144 | |
| 145 | if ( empty( $tag ) ) { |
| 146 | return strip_shortcodes( $content ) !== $content; |
| 147 | } |
144 | 148 | |
145 | 149 | if ( shortcode_exists( $tag ) ) { |
146 | 150 | preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER ); |
diff --git tests/phpunit/tests/shortcode.php tests/phpunit/tests/shortcode.php
index 08ef1ac..8dba3f8 100644
|
|
EOF; |
582 | 582 | } |
583 | 583 | |
584 | 584 | /** |
| 585 | * Tests if has_shortcode() finds any shortcode, when tag input is empty |
| 586 | * |
| 587 | * @ticket 31093 |
| 588 | */ |
| 589 | public function test_has_shortcode_should_find_any_shortcode_with_empty_tag_input() { |
| 590 | $content = 'This is a blob with [gallery] in it'; |
| 591 | $this->assertTrue( has_shortcode( $content ) ); |
| 592 | |
| 593 | $content = 'This is a blob without a shortcode in it'; |
| 594 | $this->assertFalse( has_shortcode( $content ) ); |
| 595 | |
| 596 | $content = 'This is a blob with an [foo] non-existing shortcode in it'; |
| 597 | $this->assertFalse( has_shortcode( $content ) ); |
| 598 | |
| 599 | $content_nested = 'This is a blob with [foo] [gallery] [/foo] in it'; |
| 600 | $this->assertTrue( has_shortcode( $content_nested ) ); |
| 601 | |
| 602 | add_shortcode( 'foo', '__return_empty_string' ); |
| 603 | $content = 'This is a blob with a [foo] shortcode in it'; |
| 604 | $this->assertTrue( has_shortcode( $content ) ); |
| 605 | remove_shortcode( 'foo' ); |
| 606 | } |
| 607 | |
| 608 | /** |
585 | 609 | * Make sure invalid shortcode names are not allowed. |
586 | 610 | * |
587 | 611 | * @dataProvider data_registration_bad |