[wp-trac] [WordPress Trac] #31093: Make $tag argument optional for has_shortcode()

WordPress Trac noreply at wordpress.org
Thu Jan 22 10:27:59 UTC 2015

#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 2nd-opinion  |  Resolution:
                                                |     Focuses:
Changes (by tyxla):

 * keywords:  needs-patch => has-patch dev-feedback 2nd-opinion


 Not sure if that makes sense, or if it is necessary at all.

 My point is, if a function would check for any shortcodes within the
 content, it would make more sense if a new function
 `contains_shortcodes()` is created for that purpose. Mainly because
 `has_shortcode()` would do totally different things in the two cases (with
 and without a parameter). And the function name would make more sense

 Also, I believe a function for checking whether there are any shortcodes
 is not necessary. It is quick enough to check the original string against
 the result of `strip_shortcodes()` over the string. Something like this:

 $original_content = 'some content that might have [shortcodes]';
 $stripped_content = strip_shortcodes($original_content);

 if ( $original_content === $stripped_content ) {
     echo 'There are no shortcodes within the content.';
 } else {
     echo 'There are one or more shortcodes within the content.';

 Of course, a built-in function for this can turn out handy for developers.
 Attaching a patch here (
 https://core.trac.wordpress.org/attachment/ticket/31093/31093.patch ) in
 case the core committer team decide to include it. Tests included.

Ticket URL: <https://core.trac.wordpress.org/ticket/31093#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list