Opened 6 years ago
Closed 17 months ago
#31703 closed defect (bug) (fixed)
Trying to get property of non-object in nav-menu.php
Reported by: | mehulkaklotar | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.3 | Priority: | normal |
Severity: | major | Version: | 4.2 |
Component: | Menus | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
Every time when I refresh my site, I have this PHP error : "Trying to get property of non-object" in wp-includes/nav-menu.php in line no:665. If I have something in menu that has no post titles set for that nav object then the code should check that it is set or not.
Attachments (4)
Change History (18)
#2
@
6 years ago
- Keywords has-patch added
- Milestone changed from Awaiting Review to 4.2
We have validation for taxonomy menu items here, but not for post type items.
31703.patch brings some consistency.
#3
@
6 years ago
In the code below, we have $original_object->ID, in my case the ID is also not set. which causes the error.
if ( '' === $original_title ) { $original_title = sprintf( __( '#%d (no title)' ), $original_object->ID ); }
is should be checked first. So it is better, we check for $original_object first before doing anything.
This ticket was mentioned in Slack in #core by drew. View the logs.
6 years ago
#5
follow-up:
↓ 6
@
6 years ago
- Milestone changed from 4.2 to Future Release
I'd be interested to know under what circumstances the object_id
wouldn't be set, thereby causing get_post()
to return null. Seems like we first need to identify the cause of the reported problem before we talk about solutions.
Punting to future release.
#6
in reply to:
↑ 5
@
6 years ago
Replying to DrewAPicture:
I'd be interested to know under what circumstances the
object_id
wouldn't be set, thereby causingget_post()
to return null. Seems like we first need to identify the cause of the reported problem before we talk about solutions.
Punting to future release.
Without testing, it's plausible something like BuddyPress could cause this. It inserts a custom menu group for it's logged in user profile pages that are not real pages, though even in that instance it would be on us to override any values such as these if possible, and also on us to send patches upstream if not possible.
#7
@
6 years ago
I have encountered this by deleting a Page that's currently being used in a menu. But I can't get it to happen in every instance, so I'm not sure what was different about the times when I did get that result.
#8
@
6 years ago
Replying to @DrewAPicture
I'd be interested to know under what circumstances the object_id wouldn't be set, thereby causing get_post() to return null. Seems like we first need to identify the cause of the reported problem before we talk about solutions. Punting to future release.
I got the case. I have a widget in footer which has a Custom Menu widget. Now the Menu has a shopping cart page which gives a null object for get_post()
. This page is from woocommerce page which was deleted but is present in the menu yet. So the object ID is being processed with get_post()
where it has no object to return.
checked the post_title with isset function to ensure that the post title exists if not then empty string passed which is further checked with conditions