WordPress.org

Make WordPress Core

#20998 closed defect (bug) (duplicate)

the_content filter hooks are not called when $priority is greater than 11.

Reported by: attosoft Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: General Keywords:
Focuses: Cc:

Description

the_content filter hooks in custom shortcode are not called when $priority of add_filter() is greater than 11.

I defined the following test shortcode and filter in functions.php.

function test_shortcode() {
	return apply_filters('the_content', '<p>test_shortcode</p>');
}
add_shortcode('test', 'test_shortcode');

function test_filter($text) {
	var_dump(htmlspecialchars($text));
	return $text;
}
add_filter('the_content', 'test_filter', $priority);

Then I created the post below and viewed it.

<p>test page</p>
[test]

var_dump() outputs as follows if "$priority <= 11".

string(34) "<p>test_shortcode</p> " string(64) "<p>test page</p> <p>test_shortcode</p> "

And var_dump() outputs as follows if "$priority > 11".

string(34) "<p>test_shortcode</p> "

This shows test_filter() is called from apply_filters() in test_shortcode(), but not called from apply_filters() in the_content() in wp-includes/post-template.php.

I guess there is a problem in add_filter() or apply_filter() in wp-includes/plugin.php.

Change History (1)

comment:1 scribu22 months ago

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

The key is that shortcodes are themselves implemented by a filter added to 'the_content'.

So you're effectively calling apply_filters( 'the_content' ) while 'the_content' filter is being applied.

This has been reported before: #17817

Note: See TracTickets for help on using tickets.