diff --git src/wp-includes/shortcodes.php src/wp-includes/shortcodes.php
index f052362..d2b392b 100644
|
|
|
function strip_shortcodes( $content ) {
|
| 605 | 605 | |
| 606 | 606 | // Find all registered tag names in $content. |
| 607 | 607 | preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); |
| 608 | | $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); |
| | 608 | |
| | 609 | $tags_to_remove = array_keys( $shortcode_tags ); |
| | 610 | |
| | 611 | /** |
| | 612 | * Filters the list of shortcode tags to remove from the content. |
| | 613 | * |
| | 614 | * @since 4.7.0 |
| | 615 | * |
| | 616 | * @param array $tag_array Array of shortcode tags to remove. |
| | 617 | * @param string $content Content to remove shortcode tags from. |
| | 618 | */ |
| | 619 | $tags_to_remove = apply_filters( 'strip_shortcodes_tagnames', $tags_to_remove, $content ); |
| | 620 | |
| | 621 | $tagnames = array_intersect( $tags_to_remove, $matches[1] ); |
| 609 | 622 | |
| 610 | 623 | if ( empty( $tagnames ) ) { |
| 611 | 624 | return $content; |
diff --git tests/phpunit/tests/shortcode.php tests/phpunit/tests/shortcode.php
index e807f95..ec25f76 100644
|
|
|
EOF;
|
| 340 | 340 | $this->assertEquals( $test_string, shortcode_unautop( wpautop( $test_string ) ) ); |
| 341 | 341 | } |
| 342 | 342 | |
| | 343 | function data_test_strip_shortcodes() { |
| | 344 | return array( |
| | 345 | array( 'before', 'before[gallery]' ), |
| | 346 | array( 'after', '[gallery]after' ), |
| | 347 | array( 'beforeafter', 'before[gallery]after' ), |
| | 348 | array( 'before[after', 'before[after' ), |
| | 349 | array( 'beforeafter', 'beforeafter' ), |
| | 350 | array( 'beforeafter', 'before[gallery id="123" size="medium"]after' ), |
| | 351 | array( 'before[unregistered_shortcode]after', 'before[unregistered_shortcode]after' ), |
| | 352 | array( 'beforeafter', 'before[footag]after' ), |
| | 353 | array( 'before after', 'before [footag]content[/footag] after' ), |
| | 354 | array( 'before after', 'before [footag foo="123"]content[/footag] after' ), |
| | 355 | ); |
| | 356 | } |
| | 357 | |
| 343 | 358 | /** |
| 344 | 359 | * @ticket 10326 |
| | 360 | * |
| | 361 | * @dataProvider data_test_strip_shortcodes |
| | 362 | * |
| | 363 | * @param string $expected Expected output. |
| | 364 | * @param string $content Content to run strip_shortcodes() on. |
| 345 | 365 | */ |
| 346 | | function test_strip_shortcodes() { |
| 347 | | $this->assertEquals('before', strip_shortcodes('before[gallery]')); |
| 348 | | $this->assertEquals('after', strip_shortcodes('[gallery]after')); |
| 349 | | $this->assertEquals('beforeafter', strip_shortcodes('before[gallery]after')); |
| | 366 | function test_strip_shortcodes( $expected, $content ) { |
| | 367 | $this->assertEquals( $expected, strip_shortcodes( $content ) ); |
| 350 | 368 | } |
| 351 | 369 | |
| | 370 | /** |
| | 371 | * @ticket 37767 |
| | 372 | */ |
| | 373 | function test_strip_shortcodes_filter() { |
| | 374 | add_filter( 'strip_shortcodes_tagnames', array( $this, '_filter_strip_shortcodes_tagnames' ) ); |
| | 375 | $this->assertEquals( 'beforemiddle [footag]after', strip_shortcodes( 'before[gallery]middle [footag]after' ) ); |
| | 376 | remove_filter( 'strip_shortcodes_tagnames', array( $this, '_filter_strip_shortcodes_tagnames' ) ); |
| | 377 | } |
| | 378 | |
| | 379 | function _filter_strip_shortcodes_tagnames() { |
| | 380 | return array( 'gallery' ); |
| | 381 | } |
| 352 | 382 | |
| 353 | 383 | // Store passed in shortcode_atts_{$shortcode} args |
| 354 | 384 | function _filter_atts( $out, $pairs, $atts ) { |