WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/12/2015 03:12:29 PM (6 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-term.php

    r35031 r35032  
    9797
    9898    /**
     99     * Info about the term, as stored in the database.
     100     *
     101     * @since 4.4.0
     102     * @access protected
     103     * @var array
     104     */
     105    protected $data = array();
     106
     107    /**
    99108     * Stores the term object's sanitization level.
    100109     *
     
    158167            $this->$key = $value;
    159168        }
     169
     170        $this->data = sanitize_term( $term, $this->taxonomy, $this->filter );
    160171    }
    161172
     
    183194        return get_object_vars( $this );
    184195    }
     196
     197    /**
     198     * Getter.
     199     *
     200     * @since 4.4.0
     201     * @access public
     202     *
     203     * @return mixed
     204     */
     205    public function __get( $key ) {
     206        switch ( $key ) {
     207            case 'data' :
     208                return sanitize_term( $this->{$key}, $this->data->taxonomy, 'raw' );
     209                break;
     210        }
     211    }
    185212}
Note: See TracChangeset for help on using the changeset viewer.