#16717 closed defect (bug) (fixed)
Wrong error handling in query.php::get_posts()
Reported by: | fabifott | Owned by: | |
---|---|---|---|
Milestone: | 3.1.1 | Priority: | normal |
Severity: | minor | Version: | 3.1 |
Component: | Query | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
The bug seems to be in a back compat block, so not very important:
In lines 2187 and 2199 get_term_by() is called. In following line it is just checked if it returns are logical true value.:
$the_cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' ); if ( $the_cat ) { $this->set( 'cat', $the_cat->term_id ); $this->set( 'category_name', $the_cat->slug ); }
But get_term_by calls get_term(), and this function can return WP_Error. As a result, the error is not handled properly. This caused several warnings in Debug Mode, since the WP_Error object is treated as a Category object. The bug is actually in get_term_by() since it returns false in error case by definition.
Attachments (3)
Change History (14)
#2
@
13 years ago
- Cc nerx added
- Keywords needs-patch added
This is new, I'm guessing you did play with the theme functions? Because $cat_query should not get field? if you handling in post.
#3
@
13 years ago
- Keywords needs-patch removed
- Milestone changed from Awaiting Review to 3.1.1
This code is for back compat, but it's translating the new tax_query var to the cat/category_name vars. So this should go into 3.1.1.
#6
@
13 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
hmm, #16464
Function should not return WP_Error. We've discussed that before.
@
13 years ago
Port of http://core.trac.wordpress.org/attachment/ticket/16464/16464.2.patch to trunk.
#7
@
13 years ago
The ticket here is basically a duplicate of #16464. In #16464 we came to the conclusion that get_term_by() should not return WP_Error on error but FALSE (as documented).
Previous to that conclusion there was an earlier suggestion to check for WP_Error (comparable to the changesets [17506] and [17507]) and the ticket had such a patch for weeks already (it was with a minor error which didn't get corrected because core developer feedback pointed out that the other patch is preferred).
That ticket had been put to Future Release ca. 4 weeks ago.
The new patch here is the solution of #16464 for current trunk (and it probably applies on to 3.1 branch as well.
Please review.
#9
@
13 years ago
id is inconsistent with slug and name so I think we should go forth with 16717.patch.
Thanks to rboren for confirming the method, check !is_wp_error()