WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#35462 closed defect (bug) (fixed)

update_term_cache and deleting object_id

Reported by: berengerzyla Owned by: boonebgorges
Milestone: 4.4.2 Priority: normal
Severity: normal Version: 4.4
Component: Taxonomy Keywords: fixed-major
Focuses: Cc:
PR Number:

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: @boonebgorges
4 years ago

  • Milestone changed from Awaiting Review to 4.4.2
  • Version changed from 4.4.1 to 4.4

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:

$terms = wp_get_object_terms( $p, array( 'fields' => 'all_with_object_id' ) );
update_term_cache( $terms );

Term objects will have object_id set before update_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 in wp_get_object_terms() and forcing the items through update_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.

#2 in reply to: ↑ 1 @berengerzyla
4 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 @boonebgorges
4 years ago

@berengerzyla Thanks for the pointer to Anything Order. It turns out they're doing exactly what I hypothesized:

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 @boonebgorges
4 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 36323:

Populate term cache with proper clone of term objects.

[34999] modified the cache strategy for terms in the context of
wp_get_object_terms(). As part of these changes, the object_id property of
term objects had to be unset before being cached. To avoid modifying passed-by-
reference terms, update_term_cache() attempted to make a copy of the terms
passed to the function; however, it failed to use the clone keyword, and thus
only created a reference instead of a copy.

Props berengerzyla.
Fixes #35462.

#5 @boonebgorges
4 years ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 4.4.2.

#6 @dd32
4 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 36358:

Taxonomy: Populate term cache with proper clone of term objects.

[34999] modified the cache strategy for terms in the context of
wp_get_object_terms(). As part of these changes, the object_id property of
term objects had to be unset before being cached. To avoid modifying passed-by-
reference terms, update_term_cache() attempted to make a copy of the terms
passed to the function; however, it failed to use the clone keyword, and thus
only created a reference instead of a copy.

Merges [36323] to the 4.4 branch.
Props berengerzyla.
Fixes #35462.

Note: See TracTickets for help on using tickets.