[wp-trac] [WordPress Trac] #26355: has_shortcode does not find nested shortcodes
WordPress Trac
noreply at wordpress.org
Mon Dec 2 13:07:26 UTC 2013
#26355: has_shortcode does not find nested shortcodes
--------------------------+-----------------------------
Reporter: bseddon | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Shortcodes | Version: 3.6
Severity: normal | Keywords:
--------------------------+-----------------------------
If a shortcode is nested within another shortcode, say a video tag inside
an accordion tag, has_shortcode will report false when asked if content
contains the inner video tag.
A solution is to call has_shortcode recursively if parsed tag contains
text. The modification to the existing has_shortcode is simple.
Add these two lines after the conditional test in the has_shortcode
function:
{{{#!php
if ($shortcode[5] && has_shortcode($shortcode[5], $tag))
return true;
}}}
The first part of the first line confirms the parsed tag has content and,
if so, the function is called recursively. If the nested call return
'true' then true is returned.
The full function then looks like:
{{{#!php
function has_shortcode( $content, $tag ) {
if ( shortcode_exists( $tag ) ) {
preg_match_all( '/' . get_shortcode_regex() . '/s',
$content, $matches, PREG_SET_ORDER );
if ( empty( $matches ) )
return false;
foreach ( $matches as $shortcode ) {
if ( $tag === $shortcode[2] )
return true;
if ($shortcode[5] && has_shortcode($shortcode[5],
$tag))
return true;
}
}
return false;
}
}}}
Bill Seddon
--
Ticket URL: <http://core.trac.wordpress.org/ticket/26355>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list