Make WordPress Core

Opened 21 months ago

Last modified 18 months ago

#26649 reopened defect (bug)

escaped shortcodes should not be expanded during 'get_the_excerpt'

Reported by: bobbingwide Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.7.1
Component: Shortcodes Keywords:
Focuses: Cc:


It is possible for "the_content" filter to be invoked while processing "get_the_excerpt".

If the do_shortcodes() filter hook is attached to both "the_content" and "get_the_excerpt" then this can lead to an unexpected expansion of an escaped shortcode.

This can lead to unwanted side effects, as reported here.

This minor problem can be alleviated by a simple change to strip_shortcode_tag(), returning the HTML code [ as the first character rather than the left square bracket.

function strip_shortcode_tag( $m ) {
	// allow [[foo]] syntax for escaping a tag
	if ( $m[1] == '[' && $m[6] == ']' ) {
		return "[" . substr($m[0], 2, -1) ;
	return $m[1] . $m[6];

I don't believe that it's necessary to make the same change in do_shortcode_tag().

Attachments (1)

26649.patch (648 bytes) - added by bobbingwide 21 months ago.
patch for 26649

Download all attachments as: .zip

Change History (6)

@bobbingwide21 months ago

patch for 26649

comment:1 @SergeyBiryukov21 months ago

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

Duplicate of #19927.

comment:2 follow-up: @bobbingwide21 months ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

Hi Sergey. Thanks for finding 19927 for me. I wondered why my patch had two changes.
The change in 19927 is for do_shortcode_tag()
The second part of the change, in 26649, is for strip_shortcode_tag().

The problem is not exactly a duplicate as the fix for 26649 handles the situation where shortcodes are being removed.

The patch for 26649 will work for 19927 but not vice-versa.
How should this be addressed?

comment:3 in reply to: ↑ 2 @SergeyBiryukov21 months ago

  • Milestone set to Awaiting Review

Replying to bobbingwide:

The patch for 26649 will work for 19927 but not vice-versa.

I see, thanks for the clarification. Let's close #19927 in favor if this ticket then.

comment:4 @SergeyBiryukov21 months ago

#19927 was marked as a duplicate.

Note: See TracTickets for help on using tickets.