WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#16464 closed defect (bug) (fixed)

get_term_by() returns WP_Error as well

Reported by: hakre Owned by:
Milestone: 3.1.1 Priority: normal
Severity: normal Version: 3.0
Component: Warnings/Notices Keywords:
Focuses: Cc:

Description

It's not documented, but get_term_by() can return WP_Error as well in case it fails.

Code that checks for the return value only against being not empty is doing short as WP_Error never is empty.

The result are most often undefined property warnings.

Attachments (2)

16464.2.patch (750 bytes) - added by hakre 3 years ago.
Not that invasive for existing code.
16464.patch (905 bytes) - added by hakre 3 years ago.
(updated 1x)

Download all attachments as: .zip

Change History (13)

comment:1 hakre3 years ago

The related feature is: Advanced multi-taxonomy WP_Query()s (#12891)

comment:2 hakre3 years ago

The root cause for this is that get_term() does return WP_Error.

hakre3 years ago

Not that invasive for existing code.

comment:3 hakre3 years ago

The second patch "corrects" the return value for the function get_term_by() based on the information in the function's docblock comment (return false on error).

comment:4 hakre3 years ago

  • Component changed from General to Warnings/Notices

comment:5 scribu3 years ago

Similar: #16282

comment:6 nacin3 years ago

  • Keywords 3.2-early added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 3.1 to 3.0

If that is indeed the only way for get_term_by() to return WP_Error (and that's what it looks like), then the fix looks good. They already needed to look for false anyway, so I'm fine with preventing the possibility of WP_Error being returned through get_term_by().

comment:7 hakre3 years ago

Duplicate: #16717, Related [17506], [17507]

hakre3 years ago

(updated 1x)

comment:8 ryan3 years ago

  • Milestone changed from Future Release to 3.1.1

comment:9 ryan3 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [17526]) Return false instead of WP_Error from get_term_by() if the term does not exist. Makes fetching a term by id consistent with slug and name. Props hakre. fixes #16464 #16717 for trunk

comment:10 automattor3 years ago

(In [17527]) Return false instead of WP_Error from get_term_by() if the term does not exist. Makes fetching a term by id consistent with slug and name. Props hakre. fixes #16464 #16717 for 3.1

comment:11 hakre3 years ago

  • Keywords has-patch 3.2-early removed
Note: See TracTickets for help on using tickets.