Make WordPress Core

Ticket #31093: 31093.patch

File 31093.patch, 1.7 KB (added by tyxla, 10 years ago)
  • src/wp-includes/shortcodes.php

     
    173173}
    174174
    175175/**
     176 * Whether the passed content contains any shortcodes.
     177 *
     178 *
     179 * @param string $content Content to remove shortcode tags.
     180 * @return string Content without shortcode tags.
     181 */
     182function contains_shortcodes( $content ) {
     183        $stripped_content = strip_shortcodes($content);
     184       
     185        if ( $content !== $stripped_content ) {
     186            return true;
     187        }
     188        return false;
     189}
     190
     191/**
    176192 * Search content for shortcodes and filter shortcodes through their hooks.
    177193 *
    178194 * If there are no shortcode tags defined, then the content will be returned
  • tests/phpunit/tests/shortcode.php

     
    397397                $this->assertTrue( has_shortcode( $content_nested, 'gallery' ) );
    398398                remove_shortcode( 'foo' );
    399399        }
     400
     401        /**
     402         * @ticket 31093
     403         */
     404        function test_contains_shortcodes() {
     405                $content = 'This is a blob with [gallery] in it';
     406                $this->assertTrue( contains_shortcodes( $content ) );
     407
     408                $content_nested = 'This is a blob with [foo] [gallery] [/foo] in it';
     409                $this->assertTrue( contains_shortcodes( $content_nested ) );
     410
     411                $content = 'This is a blob with no shortcodes in it';
     412                $this->assertFalse( contains_shortcodes( $content ) );
     413
     414                $content = 'This is a blob with an [example] non-existing shortcode in it';
     415                $this->assertFalse( contains_shortcodes( $content ) );
     416        }
    400417}