#37291 closed defect (bug) (fixed)
Check for WP_Error before echo in the_tags()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | fixed-major |
Focuses: | Cc: |
Description
I got Catchable fatal error: Object of class WP_Error could not be converted to string in /wp-includes/category-template.php on line 1101
on an auto updated site.
Attachments (2)
Change History (17)
#1
@
9 years ago
- Keywords has-patch needs-refresh added
- Milestone changed from Awaiting Review to Future Release
- Version trunk deleted
@michalzuber What's the code/message of the WP_Error
object?
WordPress uses tabs for indentation. I think the following would be more readable:
$tags = get_the_tag_list( $before, $sep, $after ); if ( is_wp_error( $tags ) ) { return ''; } return $tags;
#2
@
8 years ago
After debugging this on WordPress.com, I believe this deserves fixing much deeper than this as well.
In my case, it seems the issue is that get_the_terms()
is returning array( WP_Term, WP_Error, WP_Term )
- note the WP_Error in the middle, which trips up get_term_link()
and returns that WP_Error
there.
The WP_Error is a invalid_term => Empty Term
error, which appears to be caused by get_object_term_cache()
calling get_term()
on the failure of a wp_cache_get()
(which should exist, as it was just set by _prime_term_caches()
).
I suspect this is caused by out-of-sync term caches.. but not sure exactly how that's happening.
It does look like get_object_term_cache()
isn't designed to handle cases where _prime_term_caches()
doesn't cache all the terms.
Based on the code in get_object_term_cache()
I'd suggest that maybe get_term()
should be called directly rather than wp_cache_get( $term_id, 'terms' )
- and WP_Error
instances from that should be floated up the call chain.
cc @boonebgorges re [37573]
#4
@
8 years ago
- Keywords needs-testing added; needs-refresh removed
- Milestone changed from Future Release to 4.6.2
@dd32 Yes, your idea is a good one. See 37291.2.diff: if any call to get_term()
returns an error object, get_object_term_cache()
will bail, returning the WP_Error
. get_the_terms()
and friends are already built in such a way that the error object will be passed up the chain. Can you read the patch (especially the test, which tries to emulate a situation where get_term()
would return an error) to make sure it captures the spirit of your idea?
#5
@
8 years ago
@boonebgorges That looks like it does exactly what I was thinking, I was for some reason having difficulty in writing that same patch while dug in deep. I also assume there's a PHPDoc update to go with that though.
One case I was worried about was where it'd just continuously return a WP_Error
when the cache was invalid, however by switching purely to get_term()
that would cause it to fall back to the database anyway, correct?
#6
@
8 years ago
One case I was worried about was where it'd just continuously return a WP_Error when the cache was invalid, however by switching purely to get_term() that would cause it to fall back to the database anyway, correct?
Yup, all the caching logic is hidden inside of get_term()
. This is better anyway, since it means less exposure of the cache internals.
I also assume there's a PHPDoc update to go with that though.
Great, I'll add this and commit. Thanks!
#7
@
8 years ago
- Owner set to boonebgorges
- Resolution set to fixed
- Status changed from new to closed
In 38776:
#8
@
8 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for 4.6.2.
Important note: the @since
annotation added in [38776] reads 4.6.2
. If there ends up being no 4.6.2 release, that value should be changed to 4.7.0 in trunk.
Check if WP_Error