Make WordPress Core

Opened 21 months ago

Closed 19 months ago

Last modified 19 months ago

#24827 closed defect (bug) (wontfix)

bug in post-template.php

Reported by: 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)

comment:1 @johnbillion21 months 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.

comment:2 @SergeyBiryukov20 months ago

  • Component changed from General to Template

comment:3 @crysman20 months 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".

comment:4 @crysman20 months ago

  • Keywords needs-patch added; reporter-feedback removed

comment:5 @Frank Klein19 months 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.

comment:6 @SergeyBiryukov19 months 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.

comment:7 @SergeyBiryukov19 months 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 19 months ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.