Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#20998 closed defect (bug) (duplicate)

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

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


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) {
	return $text;
add_filter('the_content', 'test_filter', $priority);

Then I created the post below and viewed it.

<p>test page</p>

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)

#1 @scribu
12 years 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.