Opened 9 years ago
Closed 9 years ago
#35462 closed defect (bug) (fixed)
update_term_cache and deleting object_id
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.4.2 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Taxonomy | Keywords: | fixed-major |
Focuses: | Cc: |
Description
I have been getting a lot of errors (since -don't-remember-which-update), even preventing some pages to load.
Here it is:
PHP Notice: Undefined property: stdClass::$object_id in […]/wp-includes/taxonomy.php on line 3619
Tracked down the issue to update_object_term_cache
.
If I dump the content of the $term
there, it indeed does not have any object_id
property.
Debugged all the way up to find the culprit in update_term_cache
:
// Create a copy in case the array was passed by reference. $_term = $term; // Object ID should not be cached. unset( $_term->object_id );
I haven't checked more clearly why, but this simple copy does not work in my install. Really cloning the object with $_term = clone $term;
fixes the issue.
WP 4.1.1
PHP 7.0.1-4
nginx 1.9.7
WPML
Change History (6)
#1
follow-up:
↓ 2
@
9 years ago
- Milestone changed from Awaiting Review to 4.4.2
- Version changed from 4.4.1 to 4.4
#2
in reply to:
↑ 1
@
9 years ago
Hi @boonebgorges,
Thank you for your quick reply!
I indeed use plugins, and my first idea was to incriminate WPML, which messes up (too often) some releases.
But my track didn't lead me there, but actually to another plugin, AnythingOrder, which indeed loads and browses through the taxonomies. I will find the issue in there and will notify the plugin's author.
Sorry about the false alarm, even though the clone
might be a good safeguard there :)
Cheers and happy 2016!
#3
@
9 years ago
@berengerzyla Thanks for the pointer to Anything Order. It turns out they're doing exactly what I hypothesized:
- First, they filter
wp_get_object_terms
: https://plugins.trac.wordpress.org/browser/anything-order/tags/1.0.3/modules/taxonomy/class.php?marks=30#L17 - Then, in the filter callback, they query the database for terms - including
object_id
- and then send them throughupdate_term_cache()
before returning them. https://plugins.trac.wordpress.org/browser/anything-order/tags/1.0.3/modules/taxonomy/class.php?marks=229#L217
In this way, they cause term objects to be object_id
-free by the time they come out of wp_get_object_terms()
.
Switching to clone
ought to fix this. Thanks again for the ticket!
#4
@
9 years ago
- Owner set to boonebgorges
- Resolution set to fixed
- Status changed from new to closed
In 36323:
Hi @berengerzyla - Welcome to WordPress Trac! Thanks for opening this ticket.
I think you're correct that this ought to be
clone
. Consider the following:Term objects will have
object_id
set beforeupdate_term_cache()
, but not after. This is clearly incorrect. I assume that something like this is happening in your case.That being said, I've been unable to reproduce exactly what you've described. If my hypothesis is correct, one of two things is happening: a plugin is filtering 'wp_get_object_terms' or 'get_object_terms' and removing the
object_id
, or something is intervening inwp_get_object_terms()
and forcing the items throughupdate_term_cache()
. Your debugging makes it sound as if it's the latter, but looking at the code, I can't see how that would happen.Is there any chance you can provide a complete stack trace of the call to
update_term_cache()
that's causing the by-reference pollution of$_term
? I have a feeling it's being called by something outside of WP core, but I want to be sure that's the case before making your suggested change.