[wp-trac] [WordPress Trac] #47616: Enhancement: doing_shortcode() function similar to doing_filter()

WordPress Trac noreply at wordpress.org
Mon Apr 12 22:41:07 UTC 2021


#47616: Enhancement: doing_shortcode() function similar to doing_filter()
-------------------------------------------------+-------------------------
 Reporter:  keraweb                              |       Owner:  audrasjb
     Type:  enhancement                          |      Status:  accepted
 Priority:  normal                               |   Milestone:  5.8
Component:  Shortcodes                           |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-docs needs-dev-note  |     Focuses:
  2nd-opinion needs-unit-tests                   |
-------------------------------------------------+-------------------------

Comment (by johnjamesjacoby):

 Ran into another instance where this would have been useful.

 > Since shortcodes can be nested, it's possible to be in multiple
 shortcodes at once yet checking current_shortcode() will only return one.
 This can lead to unexpected behavior.

 Multisite and `switch_to_blog()` has/had a similar implementation concern,
 where it's "stack" of switched sites (in the
 `$GLOBALS['_wp_switched_stack']` global) has functions to navigate it.

 In the case of shortcodes, I would imagine that `current_shortcode()`
 should always return the one that is being executed ''right now'', inside
 an array or stack of the currently nested shortcode calls. That would make
 `doing_shortcode()` work similarly to `ms_is_switched()`, which it mostly
 appears to in the patch already – doing any, or doing one.

 Maybe `doing_shortcode()` could include a second parameter for if it's the
 ''right now'' shortcode or the ''anywhere in the stack'' shortcode.

 Perhaps the `$wp_current_shortcode` global should be renamed to
 `$_wp_shortcode_stack` to be consistent with others? I'm not fluent with
 the current core naming guidelines, but I'm just bringing it up since I'm
 talking about multisite above.

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


More information about the wp-trac mailing list