Make WordPress Core

Opened 10 years ago

Last modified 5 years ago

#26649 reopened defect (bug)

escaped shortcodes should not be expanded during 'get_the_excerpt'

Reported by: bobbingwide's profile bobbingwide Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.7.1
Component: Shortcodes Keywords: needs-patch needs-unit-tests
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 10 years ago.
patch for 26649

Download all attachments as: .zip

Change History (7)

10 years ago

patch for 26649

#1 @SergeyBiryukov
10 years ago

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

Duplicate of #19927.

#2 follow-up: @bobbingwide
10 years 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?

#3 in reply to: ↑ 2 @SergeyBiryukov
10 years 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.

#4 @SergeyBiryukov
10 years ago

#19927 was marked as a duplicate.

#6 @chriscct7
9 years ago

  • Keywords needs-patch needs-unit-tests added
Note: See TracTickets for help on using tickets.