[wp-trac] [WordPress Trac] #33275: do_shortcode change in nested shortcode behaviour in 4.2.3 due to do_shortcodes_in_html_tags

WordPress Trac noreply at wordpress.org
Wed Aug 5 09:47:49 UTC 2015


#33275: do_shortcode change in nested shortcode behaviour in 4.2.3 due to
do_shortcodes_in_html_tags
--------------------------+-----------------------------
 Reporter:  chrisl27      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Shortcodes    |    Version:  4.2.3
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Processing of nested shortcodes changed behaviour in 4.2.3, as the
 do_shortcodes_in_html_tags is processing the shortcodes inside the
 $content of a shortcode too soon.

 Previously to 4.2.3 with the following snippet:

 {{{[short1]<a [short2]>[short2]</a>[/short1]}}}

 short1 would have been passed {{{<a [short2]>[short2]</a>}}} as the
 content

 However in 4.2.3, short1 is being passed {{{<a 0>[short2]</a>}}} (short2
 is a function that returns "0")

 This is because do_shortcodes_in_html_tags has over-aggressively dived
 into the nested content to run the shortcode inside the attribute (this is
 different from the standard behaviour, where shortcodes outside attributes
 are *not* normally run).

 This means that shortcodes that rely on state are no longer being run in
 the right order. For example, if the behaviour of short2 is different
 depending on whether it is being run inside short1, you get two different
 eventual outputs.

 Full code example follows:
 {{{
 global $state;
 $state = 0;

 function short1_func($atts, $content) {
   echo "short1 was passed $content\n";
   global $state;
   $state++;
   return do_shortcode($content);
 }
 add_shortcode('short1', 'short1_func');

 function short2_func($atts) {
   global $state;
   return $state;
 }
 add_shortcode('short2', 'short2_func');

 var_dump(do_shortcode('<a [short2]>[short2]</a>'));
 var_dump(do_shortcode('[short1]<a [short2]>[short2]</a>[/short1]'));
 }}}

 Output pre-4.2.3:
 {{{
 string(10) "<a 0>0</a>"
 short1 was passed <a [short2]>[short2]</a>
 string(10) "<a 1>1</a>"
 }}}
 Output in 4.2.3:
 {{{
 string(10) "<a 0>0</a>"
 short1 was passed <a 0>[short2]</a>
 string(10) "<a 0>1</a>"
 }}}

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


More information about the wp-trac mailing list