Ticket #37767: rde-37767.patch
File rde-37767.patch, 3.2 KB (added by , 8 years ago) |
---|
-
src/wp-includes/shortcodes.php
583 583 * @global array $shortcode_tags 584 584 * 585 585 * @param string $content Content to remove shortcode tags. 586 * @param array $tag_array Optional. Array of tags to remove. 586 587 * @return string Content without shortcode tags. 587 588 */ 588 function strip_shortcodes( $content ) {589 function strip_shortcodes( $content, $tag_array = false ) { 589 590 global $shortcode_tags; 590 591 591 592 if ( false === strpos( $content, '[' ) ) { … … 597 598 598 599 // Find all registered tag names in $content. 599 600 preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); 600 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );601 601 602 // If $tag_array is set, then use this instead of global 603 $array_to_check = $shortcode_tags; 604 if($tag_array){ 605 if(isset($tag_array[ 0 ])){ 606 $array_to_check = $tag_array; 607 } else { 608 $array_to_check = array_keys( $tag_array ); 609 } 610 } else { 611 $array_to_check = array_keys( $shortcode_tags ); 612 } 613 614 $tagnames = array_intersect($array_to_check, $matches[1] ); 615 602 616 if ( empty( $tagnames ) ) { 603 617 return $content; 604 618 } -
tests/phpunit/tests/shortcode.php
340 340 $this->assertEquals( $test_string, shortcode_unautop( wpautop( $test_string ) ) ); 341 341 } 342 342 343 344 function _foobar_func( $atts ){ 345 return "foo and bar"; 346 } 347 348 343 349 /** 344 350 * @ticket 10326 345 351 */ 346 352 function test_strip_shortcodes() { 353 add_shortcode( 'foobar', '_foobar_func' ); 354 347 355 $this->assertEquals('before', strip_shortcodes('before[gallery]')); 348 356 $this->assertEquals('after', strip_shortcodes('[gallery]after')); 349 357 $this->assertEquals('beforeafter', strip_shortcodes('before[gallery]after')); 358 $this->assertEquals('before[after', strip_shortcodes('before[after')); 359 $this->assertEquals('beforeafter', strip_shortcodes('beforeafter')); 360 $this->assertEquals('beforeafter', strip_shortcodes('before[gallery id="123" size="medium"]after')); 361 $this->assertEquals('before[unregistered_shortcode]after', strip_shortcodes('before[unregistered_shortcode]after')); 362 $this->assertEquals('beforeafter', strip_shortcodes('before[foobar]after')); 363 $this->assertEquals('before after', strip_shortcodes('before [foobar]content[/foobar] after')); 364 $this->assertEquals('before after', strip_shortcodes('before [foobar id="123"]content[/foobar] after')); 365 366 $this->assertEquals('before after', strip_shortcodes('[gallery]before [foobar]after', 367 array( 'gallery' => '_gallery_func', 'foobar' => '_foobar_func' ) 368 )); 369 370 $this->assertEquals('before [foobar]after', strip_shortcodes('[gallery]before [foobar]after', 371 array( 'gallery' => '_gallery_func' ) 372 )); 373 374 $this->assertEquals('before after', strip_shortcodes('[gallery]before [foobar]after', 375 array( 'gallery', 'foobar' ) 376 )); 377 378 $this->assertEquals('before [foobar]after', strip_shortcodes('[gallery]before [foobar]after', 379 array( 'gallery' ) 380 )); 381 382 remove_shortcode( 'foobar' ); 350 383 } 351 384 352 385