[wp-trac] [WordPress Trac] #35216: Return empty string from wp.shortcode.replace() callback is ignored

WordPress Trac noreply at wordpress.org
Wed Jun 27 04:46:19 UTC 2018


#35216: Return empty string from wp.shortcode.replace() callback is ignored
--------------------------+------------------------------
 Reporter:  prionkor      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Shortcodes    |     Version:  3.5
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  javascript
--------------------------+------------------------------
Changes (by talldanwp):

 * keywords:  needs-patch => has-patch


Comment:

 I've attached 35216.diff.

 This change makes `wp.shortcode.replace()` behave more like its php
 counterpart `do_shortcode`

 If the result of the callback is a string, number or truthy value, we
 replace the shortcode with that value (so therefore if an empty string is
 returned from the callback we'll see the desired behaviour).

 For other falsey values that are not strings or numbers returned from the
 callback, the shortcode and shortcode content will be removed

 Tests have been added for the various values that might be returned from
 the callback (empty string, null, undefined, 0, empty string)

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


More information about the wp-trac mailing list