[wp-trac] [WordPress Trac] #26927: Fix docs of shortcode_parse_atts()

WordPress Trac noreply at wordpress.org
Fri Jan 24 18:09:12 UTC 2014


#26927: Fix docs of shortcode_parse_atts()
-------------------------+-----------------------------
 Reporter:  TobiasBg     |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Shortcodes   |    Version:  2.5
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 While debugging an issue with a Shortcode without attributes, like
 `[shortcode]`, I tripped over the unexpected return value of
 `shortcode_parse_atts()` in that case (an empty string).
 Instead of returning an (empty) array, which would be much more fitting
 and in line with what the function does, it returns an (empty) string.

 The problem: This was added in [6939] for #5892 six years ago. :-/
 I'm not exactly sure for what cases this was necessary after [6911] for
 #5914 was already in, but presumably there's some edge case strings that
 the huge regex in `shortcode_parse_atts()` does not match.

 I would love to make `shortcode_parse_atts()` return arrays consistently,
 especially as most people paste the return value to `shortcode_atts()`
 which per documentation expects an array (but also accepts the string), or
 explicitely use it as an array in their Shortcode handlers.
 It should be enough to change the return value in the
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/shortcodes.php#L316 else branch] to
 {{{
 $atts = array( ltrim($text) );
 }}}

 However, as this has been around for six years, and as the edge case with
 the empty string is mentioned in the
 [http://codex.wordpress.org/Shortcode_API#Overview], and as we have
 specific
 [https://core.trac.wordpress.org/browser/trunk/tests/phpunit/tests/shortcode.php#L76
 unit tests] that check for that empty string, we probably can't change
 this without breaking back-compat for some plugins :-(

 Then, at least, let's fix the inline docs to make the return value clear.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/26927>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list