Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#16464 closed defect (bug) (fixed)

get_term_by() returns WP_Error as well

Reported by: hakre's profile 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 14 years ago.
Not that invasive for existing code.
16464.patch (905 bytes) - added by hakre 14 years ago.
(updated 1x)

Download all attachments as: .zip

Change History (13)

#1 @hakre
14 years ago

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

#2 @hakre
14 years ago

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

@hakre
14 years ago

Not that invasive for existing code.

#3 @hakre
14 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
14 years ago

  • Component changed from General to Warnings/Notices

#5 @scribu
14 years ago

Similar: #16282

#6 @nacin
14 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().

#7 @hakre
14 years ago

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

@hakre
14 years ago

(updated 1x)

#8 @ryan
14 years ago

  • Milestone changed from Future Release to 3.1.1

#9 @ryan
14 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

#10 @automattor
14 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
14 years ago

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