#24250 closed defect (bug) (fixed)
Notice thrown in get_page_template_slug in certain conditions
| Reported by: | tollmanz | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.6 |
| Component: | Template | Version: | 3.4 |
| Severity: | minor | Keywords: | |
| Cc: | Focuses: |
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:
- Remove all posts from site (or just trash them)
- Add the test code below to Twenty Thirteen's functions.php (making sure that Twenty Thirteen is activated)
- Load the front page
- 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)
Change History (6)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
The diff file also improves the
$post_idPHPDoc as it can be null as well as an int.