Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#34262 closed defect (bug) (fixed)

`get_the_terms()` should not cache `WP_Term` objects

Reported by: boonebgorges's profile boonebgorges Owned by: boonebgorges's profile boonebgorges
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords:
Focuses: Cc:


get_the_terms() populates the object-term cache with the output of wp_get_object_terms(). After [34997], wp_get_object_terms() returns an array of WP_Term objects, which means that these objects are being cached. We shouldn't be doing this. WP_Term objects may have more data than ought to be stored in the cache.

Change History (3)

#1 @boonebgorges
9 years ago

In 35030:

Fix incorrect setup in 'tag' query var test.

The test, introduced in [33724], was intended to demonstrate the behavior of routing. But an error in the test setup meant that a
URL-encoded tag object was being set as the value of 'tag'. Due to a quirk in
the way that parse_request() parses query vars, an object value for 'tag'
would inadvertently produce correct results in certain cases. But it's not a
usage we actively support, and it's not what was meant to be tested.

See #33532, #34262.

#2 @boonebgorges
9 years ago

In 35031:

Be stricter about sanitizing values coming out of WP_Term.

Data passed into get_instance() should be run through sanitize_term()
before being used.

See #34262.

#3 @boonebgorges
9 years ago

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

In 35032:

Don't cache WP_Term objects in wp_get_object_cache().

The data stored in the cache should be raw database query results, not
WP_Term objects (which may be modified by plugins, and may contain additional
properties that shouldn't be cached).

If term relationships caches were handled in wp_get_object_terms() - where
a database query takes place - it would be straightforward to cache raw data.
See #34239. Since, in fact, get_the_terms() caches the value it gets from
wp_get_object_terms(), we need a technique that allows us to get raw data
from a WP_Term object. Mirroring WP_User, we introduce a data property
on term objects, which get_the_terms() uses to fetch cacheable term info.

Fixes #34262.

Note: See TracTickets for help on using tickets.