WordPress.org

Make WordPress Core

Changeset 29197


Ignore:
Timestamp:
07/16/2014 10:04:08 PM (6 years ago)
Author:
wonderboymusic
Message:

Make has_shortcode() recursive/work for nested shortcodes.

Adds unit test.

Props katzwebdesign.
Fixes #26343.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/shortcodes.php

    r28413 r29197  
    166166
    167167        foreach ( $matches as $shortcode ) {
    168             if ( $tag === $shortcode[2] )
     168            if ( $tag === $shortcode[2] ) {
    169169                return true;
     170            } elseif ( isset( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag ) ) {
     171                return has_shortcode( $shortcode[5], $tag );
     172            }
    170173        }
    171174    }
  • trunk/tests/phpunit/tests/shortcode.php

    r28716 r29197  
    395395        }
    396396    }
     397
     398    /**
     399     * @ticket 26343
     400     */
     401    function test_has_shortcode() {
     402        $content = 'This is a blob with [gallery] in it';
     403        $this->assertTrue( has_shortcode( $content, 'gallery' ) );
     404
     405        add_shortcode( 'foo', '__return_false' );
     406        $content_nested = 'This is a blob with [foo] [gallery] [/foo] in it';
     407        $this->assertTrue( has_shortcode( $content_nested, 'gallery' ) );
     408        remove_shortcode( 'foo' );
     409    }
    397410}
Note: See TracChangeset for help on using the changeset viewer.