WordPress.org

Make WordPress Core

Opened 15 months ago

Closed 12 months ago

Last modified 12 months ago

#23340 closed defect (bug) (duplicate)

get_page_template_slug( $post_id = null ) needs hardening against the null scenario

Reported by: lkraav Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.2
Component: Template Keywords:
Focuses: Cc:

Description

My pre_get_posts action overrides a plugin's query:

$q->init();
$q->set( "page_id", icl_object_id( get_option( "mp_store_page" ), "page", true ) );
$q->parse_query();

This causes, among other things:

NOTICE: wp-includes/post-template.php:1270 - Trying to get property of non-object

To me, it looks strange that the function's signature sort of accounts for this scenario, but in the function there's no handling for when it actually happens at

if ( 'page' != $post->post_type )

Change History (3)

comment:1 lkraav15 months ago

Also see #18750 #21790

Backtrace:

#0  get_page_template_slug() called at [/home/markitek/public_html/project/wp-includes/template.php:228]
#1  get_page_template() called at [/home/markitek/public_html/project/wp-includes/template-loader.php:31]
#2  require_once(/home/markitek/public_html/project/wp-includes/template-loader.php) called at [/home/markitek/public_html/project/wp-blog-header.php:16]
#3  require(/home/markitek/public_html/project/wp-blog-header.php) called at [/home/markitek/public_html/project/index.php:17]
Last edited 15 months ago by lkraav (previous) (diff)

comment:2 SergeyBiryukov12 months ago

  • Milestone Awaiting Review deleted
  • Status changed from new to closed

Duplicate of #24250.

comment:3 SergeyBiryukov12 months ago

  • Resolution set to duplicate
Note: See TracTickets for help on using tickets.