Make WordPress Core

Opened 4 years ago

Last modified 3 years ago

#40309 new defect (bug)

Notice: in canonical.php line 122

Reported by: bobbingwide Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0
Component: Canonical Keywords: has-patch
Focuses: Cc:



  • Attempted to access a post using ?p=22781
  • Post 22781 exists.
  • But it has a post type associated with a plugin that's been deactivated.

Expected result

404 page without a notice

Actual result

404 page with the following Notice
Notice: Trying to get property of non-object in wp-includes\canonical.php on line 122


The post_type is not registered so this returns null

$post_type_obj = get_post_type_object($redirect_post->post_type);

Proposed solution

Add test on $post_type_obj.

if ( $post_type_obj && $post_type_obj->public && 'auto-draft' != $redirect_post->post_status ) {

Workaround =

Either re-activate the de-activated plugin, or use the correct post ID... I meant to type ?p=22871

Attachments (1)

40309.diff (855 bytes) - added by bobbingwide 4 years ago.
Test $post_type_obj before accessing public property

Download all attachments as: .zip

Change History (5)

4 years ago

Test $post_type_obj before accessing public property

#1 @bobbingwide
4 years ago

  • Keywords has-patch added

#2 @swissspidy
4 years ago

  • Milestone changed from Awaiting Review to 4.8
  • Version changed from trunk to 3.0

This ticket was mentioned in Slack in #core by obenland. View the logs.

3 years ago

#4 @obenland
3 years ago

  • Milestone changed from 4.8 to Future Release
Note: See TracTickets for help on using tickets.