Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#24827 closed defect (bug) (wontfix)

bug in post-template.php

Reported by: crysman's profile crysman Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5.2
Component: Template Keywords:
Focuses: Cc:


The bug

There is a bug in wp-includes/post-template.php, line 208:

if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )

$post variable is being inicialized on line 183 like this:

$post = get_post();

What is wrong is that get_post() may return NULL, and it sometimes does. So the code


is obviously incorrect, because it is trying to access an object, which does not exist. Therefore, you get a PHP notice, thus getting "header already send" errors...

the fix

is simple - just check first if non-empty:

	if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )

Change History (7)

#1 @johnbillion
11 years ago

  • Keywords reporter-feedback added

In what situation might get_post() return null here? The function get_the_content() should only get called inside the loop where there'll be a global post object.

#2 @SergeyBiryukov
11 years ago

  • Component changed from General to Template

#3 @crysman
11 years ago

It is not about what it "might return". It is actually returning it, that is why I came up to this bug in the first place.

Problems occured after installing Content Headings Tree plugin.

But I don't think the plugin contains an error, because this is obviously a core bug - you cannot access an undefined variable/object... You cannot think like "OK, this function might return NULL but it will not I hope".

#4 @crysman
11 years ago

  • Keywords needs-patch added; reporter-feedback removed

#5 @Frank Klein
11 years ago

  • Cc contact@… added
  • Keywords needs-patch removed
  • Resolution set to invalid
  • Status changed from new to closed

The ​Content Headings Tree plugin uses the get_the_content() function outside the loop without passing any arguments, which is the source of the error.

#6 @SergeyBiryukov
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution changed from invalid to wontfix

Yes, we should not hide notices caused by plugin or theme bugs. That would only make debugging harder.

#7 @SergeyBiryukov
11 years ago

For reference, looks like the error is in lib/replaceTags.php, line 3:

That file is included on plugin loading, which is too early to use any template tags:

Last edited 11 years ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.