Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#24250 closed defect (bug) (fixed)

Notice thrown in get_page_template_slug in certain conditions

Reported by: tollmanz's profile tollmanz Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 3.6 Priority: normal
Severity: minor Version: 3.4
Component: Template Keywords:
Focuses: Cc:

Description

When get_page_template_slug() is called outside of the loop and get_post returns null, the check of $post->post_type will trigger the notice:

Notice: Trying to get property of non-object in /path/to/root/wp-includes/post-template.php on line 1284

Steps to reproduce:

  1. Remove all posts from site (or just trash them)
  2. Add the test code below to Twenty Thirteen's functions.php (making sure that Twenty Thirteen is activated)
  3. Load the front page
  4. Notice will appear


function test_get_page_template_slug() {
	get_page_template_slug();
}
add_action( 'init', 'test_get_page_template_slug' );

I'm marking as 3.4 since get_page_template_slug() was introduced then.

Attachments (1)

24250.diff (944 bytes) - added by tollmanz 12 years ago.

Download all attachments as: .zip

Change History (6)

@tollmanz
12 years ago

#1 @tollmanz
12 years ago

The diff file also improves the $post_id PHPDoc as it can be null as well as an int.

#2 @SergeyBiryukov
12 years ago

  • Milestone changed from Awaiting Review to 3.6

#3 @SergeyBiryukov
12 years ago

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

In 24191:

Avoid a PHP notice in get_page_template_slug() if the page does not exist. props tollmanz. fixes #24250.

#4 @lkraav
12 years ago

  • Cc leho@… added

#5 @SergeyBiryukov
12 years ago

#23340 was marked as a duplicate.

Note: See TracTickets for help on using tickets.