Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#16464 closed defect (bug) (fixed)

get_term_by() returns WP_Error as well

Reported by: hakre Owned by:
Priority: normal Milestone: 3.1.1
Component: Warnings/Notices Version: 3.0
Severity: normal Keywords:
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 2 years ago.
Not that invasive for existing code.
16464.patch (905 bytes) - added by hakre 2 years ago.
(updated 1x)

Download all attachments as: .zip

Change History (13)

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

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

hakre2 years ago

Not that invasive for existing code.

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).

  • Component changed from General to Warnings/Notices

Similar: #16282

  • 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().

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

hakre2 years ago

(updated 1x)

comment:8   ryan2 years ago

  • Milestone changed from Future Release to 3.1.1

comment:9   ryan2 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

(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

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