Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 2 years ago

#20519 closed defect (bug) (fixed)

PHP Notice in get_single_template()

Reported by: markjaquith Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.0
Component: Warnings/Notices Keywords: has-patch commit
Focuses: Cc:


PHP Notice: Trying to get property of non-object in wp-includes/template.php on line 283

These get_*_template() functions make a lot of assumptions about the current state of the environment.

Attachments (2)

validate-template-vars.diff (3.1 KB) - added by wonderboymusic 3 years ago.
20519.diff (2.8 KB) - added by ryan 3 years ago.

Download all attachments as: .zip

Change History (9)

#1 @SergeyBiryukov
4 years ago

Related: #17662, #18614

Last edited 4 years ago by SergeyBiryukov (previous) (diff)

#2 @nacin
4 years ago

  • Version changed from 3.4 to 3.0

#3 @wonderboymusic
3 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 3.5

This patch has basic validation for the passing of vars to template file names

#4 @nacin
3 years ago

I think in most cases it should be enough to validate we have an object. So rather than:

if ( isset( $author->user_nicename ) )
 	$templates[] = "author-{$author->user_nicename}.php";
if ( isset( $author->ID ) )
        $templates[] = "author-{$author->ID}.php";

We can do:

if ( $author ) {
 	$templates[] = "author-{$author->user_nicename}.php";
        $templates[] = "author-{$author->ID}.php";

3 years ago

#5 @ryan
3 years ago

  • Keywords commit added

#6 @ryan
3 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [22293]:

Avoid notices in get_*_template() functions that use get_queried_object(), which can return null. Props wonderboymusic. fixes #20519

#7 @chriscct7
2 years ago

I believe this still happens, and I opened a new ticket here on it: http://core.trac.wordpress.org/ticket/25398

Note: See TracTickets for help on using tickets.