Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 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: Focuses:

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 16 years ago.
Not that invasive for existing code.
16464.patch​ (905 bytes ) - added by hakre 16 years ago.
(updated 1x)

Download all attachments as: .zip

Change History (13)

#1 @hakre
16 years ago

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

#2 @hakre
16 years ago

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

@hakre
16 years ago

Not that invasive for existing code.

#3 @hakre
16 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).

#4 @hakre
16 years ago

  • Component General → Warnings/Notices

#5 @scribu
16 years ago

Similar: #16282

#6 @nacin
16 years ago

  • Keywords 3.2-early added
  • Milestone Awaiting Review → Future Release
  • Version 3.1 → 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().

#7 @hakre
16 years ago

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

@hakre
16 years ago

(updated 1x)

#8 @ryan
16 years ago

  • Milestone Future Release → 3.1.1

#9 @ryan
16 years ago

  • Resolution → fixed
  • Status new → 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

#10 @automattor
16 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

#11 @hakre
16 years ago

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