[wp-trac] [WordPress Trac] #25435: Introduce alternative to do_shortcode( '[shortcode]' )

WordPress Trac noreply at wordpress.org
Tue Feb 28 08:55:22 UTC 2017


#25435: Introduce alternative to do_shortcode( '[shortcode]' )
-------------------------------------------------+-------------------------
 Reporter:  jdgrimes                             |       Owner:  rmccue
     Type:  feature request                      |      Status:  assigned
 Priority:  normal                               |   Milestone:  4.8
Component:  Shortcodes                           |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  refresh                                        |
-------------------------------------------------+-------------------------

Comment (by aaemnnosttv):

 How about simply `call_shortcode( $tag, $atts, $content )` ? I realize
 this is only slightly different than the original suggestion, but that's
 what I came up with before I knew about this ticket.

 Here's my implementation:
 https://gist.github.com/aaemnnosttv/0751dea2121db3a859fa

 For what it's worth, I think it would be better return an empty string
 than a `WP_Error` if the shortcode callback isn't callable since this is
 basically a template function. `get_template_part()` doesn't do this, and
 dealing with a `WP_Error` in the template just seems gross, as well as
 potentially causing real errors if it isn't properly checked for: (`PHP
 Catchable fatal error:  Object of class WP_Error could not be converted to
 string in ...`). A bit worse than not showing anything IMO.

 We already have `shortcode_exists()`, using a `WP_Error` here seems a bit
 unnecessary, although I admit they do check different things. What if
 `shortcode_exists()` checked if the callback is callable as well?

 I trigger a PHP notice in my implementation, but perhaps an action could
 be fired instead, similar to a `wp_mail()` failure?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/25435#comment:27>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list