[wp-trac] [WordPress Trac] #31093: Make $tag argument optional for has_shortcode()
WordPress Trac
noreply at wordpress.org
Tue Oct 31 09:25:18 UTC 2017
#31093: Make $tag argument optional for has_shortcode()
-------------------------------------------------+-------------------------
Reporter: danielbachhuber | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future
Component: Shortcodes | Release
Severity: normal | Version:
Keywords: has-patch dev-feedback has-unit- | Resolution:
tests | Focuses:
-------------------------------------------------+-------------------------
Changes (by birgire):
* keywords: has-patch dev-feedback needs-unit-tests => has-patch dev-
feedback has-unit-tests
Comment:
I remember assuming this would work:
{{{
has_shortcode( $content )
}}}
to check for any shortcode in a content, so I support this feature.
I would prefer to use {{{has_shortcode()}}} though, instead of a new
function.
[attachment:31093.5.diff] adds a support to check if there's any shortcode
in a text, by using the clever idea from @tyxla, where I simplified it
with:
{{{
if ( empty( $tag ) ) {
return strip_shortcodes( $content ) !== $content;
}
}}}
Here we're talking about this kind of usage:
{{{
has_shortcode( $content );
has_shortcode( $content, 'gallery' );
}}}
In [attachment:31093.4.diff] I updated the patch from @ashfame, in
addition with the update from [attachment:31093.4.diff], with various
tests. Here we're talking about this kind of usage:
{{{
has_shortcode( $content );
has_shortcode( $content, 'gallery' );
has_shortcode( $content, array( 'gallery', 'playlist' ) ); // default OR
has_shortcode( $content, array( 'gallery', 'playlist' ), 'OR' );
has_shortcode( $content, array( 'gallery', 'playlist' ), 'AND' );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/31093#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list