Ticket #37767: 37767.diff
File 37767.diff, 3.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/shortcodes.php
diff --git src/wp-includes/shortcodes.php src/wp-includes/shortcodes.php index b2aad3d..d85dbd3 100644
function shortcode_atts( $pairs, $atts, $shortcode = '' ) { 579 579 * Remove all shortcode tags from the given content. 580 580 * 581 581 * @since 2.5.0 582 * @since 4.7.0 The `$tag_array` parameter was introduced. 582 583 * 583 584 * @global array $shortcode_tags 584 585 * 585 * @param string $content Content to remove shortcode tags. 586 * @param string $content Content to remove shortcode tags. 587 * @param array $tag_array Optional. Array of shortcode tags to remove. Default all tags. 586 588 * @return string Content without shortcode tags. 587 589 */ 588 function strip_shortcodes( $content ) {590 function strip_shortcodes( $content, $tag_array = array() ) { 589 591 global $shortcode_tags; 590 592 591 593 if ( false === strpos( $content, '[' ) ) { … … function strip_shortcodes( $content ) { 597 599 598 600 // Find all registered tag names in $content. 599 601 preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); 600 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 602 603 // If $tag_array is set, then use this instead of the global. 604 $tags_to_remove = empty( $tag_array ) ? array_keys( $shortcode_tags ) : $tag_array; 605 606 $tagnames = array_intersect( $tags_to_remove, $matches[1] ); 601 607 602 608 if ( empty( $tagnames ) ) { 603 609 return $content; -
tests/phpunit/tests/shortcode.php
diff --git tests/phpunit/tests/shortcode.php tests/phpunit/tests/shortcode.php index f5e8ae2..e86693e 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]', array() ), 346 array( 'after', '[gallery]after', array() ), 347 array( 'beforeafter', 'before[gallery]after', array() ), 348 array( 'before[after', 'before[after', array() ), 349 array( 'beforeafter', 'beforeafter', array() ), 350 array( 'beforeafter', 'before[gallery id="123" size="medium"]after', array() ), 351 array( 'before[unregistered_shortcode]after', 'before[unregistered_shortcode]after', array() ), 352 array( 'beforeafter', 'before[footag]after', array() ), 353 array( 'before after', 'before [footag]content[/footag] after', array() ), 354 array( 'before after', 'before [footag foo="123"]content[/footag] after', array() ), 355 array( 'before after', '[gallery]before [footag]after', array( 'gallery', 'footag' ) ), 356 array( 'before [footag]after', '[gallery]before [footag]after', array( 'gallery' ) ), 357 ); 358 } 359 343 360 /** 344 361 * @ticket 10326 362 * @ticket 37767 363 * 364 * @dataProvider data_test_strip_shortcodes 365 * 366 * @param string $expected Expected output. 367 * @param string $content Content to run strip_shortcodes() on. 368 * @param array $tag_array The specific tags to remove. 345 369 */ 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')); 370 function test_strip_shortcodes( $expected, $content, $tag_array ) { 371 $this->assertEquals( $expected, strip_shortcodes( $content, $tag_array ) ); 350 372 } 351 373 352 353 374 // Store passed in shortcode_atts_{$shortcode} args 354 375 function _filter_atts( $out, $pairs, $atts ) { 355 376 $this->filter_atts_out = $out;