Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#37292 closed defect (bug) (wontfix)

Check if $category is object before outputting

Reported by: michalzuber Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords:
Focuses: Cc:


After auto upgrade I got a Notice: Trying to get property of non-object in /wp-includes/category-template.php on line 238
with WP version 4.2.9
Upgrade was from 4.2.7 as I can remember.

Attachments (1)

37292.diff (519 bytes) - added by michalzuber 5 years ago.
Check if is object

Download all attachments as: .zip

Change History (4)

5 years ago

Check if is object

#1 @swissspidy
5 years ago

Does this still occur using the latest version of WordPress (4.5.3) and 4.6 Beta 1?

#2 @michalzuber
5 years ago

Tried to migrate the database to use the same data with the new code (trunk) and it worked.
But it would be great to check before using the object. The same might happen and this prevents it. Surely this is only Notice and errors on production should be turned off so not a big issue.

#3 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

The patch is for get_the_category_list(), which retrieves the $categories array via get_the_category().

get_the_category() always returns an array of objects, so if invalid data is encountered, it's likely because a plugin or theme did something wrong with the the_category_list, get_the_terms, or wp_get_object_terms filter, which would be a developer error.

I don't think we should hide developer errors, a notice seems perfectly fine here. Feel free to reopen if you can still reproduce the issue on a clean install with no plugins installed and a default theme activated.

Note: See TracTickets for help on using tickets.