Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#33275 closed defect (bug) (duplicate)

do_shortcode change in nested shortcode behaviour in 4.2.3 due to do_shortcodes_in_html_tags

Reported by: chrisl27's profile chrisl27 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2.3
Component: Shortcodes Keywords:
Focuses: Cc:

Description

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>"

Change History (1)

#1 @miqrogroove
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #33134.

Note: See TracTickets for help on using tickets.