Changeset 37573 for trunk/src/wp-includes/taxonomy.php
- Timestamp:
- 05/26/2016 04:49:10 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r37572 r37573 3240 3240 * Retrieves the taxonomy relationship to the term object id. 3241 3241 * 3242 * Upstream functions (like `get_the_terms()` and `is_object_in_term()`) are responsible for populating the 3243 * object-term relationship cache. The current function only fetches relationship data that is already in the cache. 3244 * 3242 3245 * @since 2.3.0 3243 3246 * 3244 3247 * @param int $id Term object ID. 3245 3248 * @param string $taxonomy Taxonomy name. 3246 * @return bool|mixed Empty array if $terms found, but not `$taxonomy`. False if nothing is in cache 3247 * for `$taxonomy` and `$id`. 3249 * @return bool|array Array of `WP_Term` objects, if cached False if cache is empty for `$taxonomy` and `$id`. 3248 3250 */ 3249 3251 function get_object_term_cache( $id, $taxonomy ) { 3250 return wp_cache_get( $id, "{$taxonomy}_relationships" ); 3252 $_term_ids = wp_cache_get( $id, "{$taxonomy}_relationships" ); 3253 3254 // We leave the priming of relationship caches to upstream functions. 3255 if ( false === $_term_ids ) { 3256 return false; 3257 } 3258 3259 // Backward compatibility for if a plugin is putting objects into the cache, rather than IDs. 3260 $term_ids = array(); 3261 foreach ( $_term_ids as $term_id ) { 3262 if ( is_numeric( $term_id ) ) { 3263 $term_ids[] = intval( $term_id ); 3264 } elseif ( isset( $term_id->term_id ) ) { 3265 $term_ids[] = intval( $term_id->term_id ); 3266 } 3267 } 3268 3269 // Fill the term objects. 3270 _prime_term_caches( $term_ids ); 3271 3272 $terms = array(); 3273 foreach ( $term_ids as $term_id ) { 3274 $terms[] = wp_cache_get( $term_id, 'terms' ); 3275 } 3276 3277 return array_map( 'get_term', $terms ); 3251 3278 } 3252 3279 … … 3298 3325 3299 3326 $object_terms = array(); 3300 foreach ( (array) $terms as $term ) 3301 $object_terms[$term->object_id][$term->taxonomy][] = $term; 3327 foreach ( (array) $terms as $term ) { 3328 $object_terms[ $term->object_id ][ $term->taxonomy ][] = $term->term_id; 3329 } 3302 3330 3303 3331 foreach ( $ids as $id ) { … … 3503 3531 if ( isset($terms_by_id[$id]) ) 3504 3532 $terms_by_id[$id]->count = count($items); 3533 } 3534 3535 /** 3536 * Adds any terms from the given IDs to the cache that do not already exist in cache. 3537 * 3538 * @since 4.6.0 3539 * @access private 3540 * 3541 * @global wpdb $wpdb WordPress database abstraction object. 3542 * 3543 * @param array $term_ids Array of term IDs. 3544 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 3545 */ 3546 function _prime_term_caches( $term_ids, $update_meta_cache = true ) { 3547 global $wpdb; 3548 3549 $non_cached_ids = _get_non_cached_ids( $term_ids, 'terms' ); 3550 if ( ! empty( $non_cached_ids ) ) { 3551 $fresh_terms = $wpdb->get_results( sprintf( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); 3552 3553 update_term_cache( $fresh_terms, $update_meta_cache ); 3554 3555 if ( $update_meta_cache ) { 3556 update_termmeta_cache( $non_cached_ids ); 3557 } 3558 } 3505 3559 } 3506 3560 … … 4212 4266 if ( false === $object_terms ) { 4213 4267 $object_terms = wp_get_object_terms( $object_id, $taxonomy, array( 'update_term_meta_cache' => false ) ); 4214 wp_cache_set( $object_id, $object_terms, "{$taxonomy}_relationships" );4268 wp_cache_set( $object_id, wp_list_pluck( $object_terms, 'term_id' ), "{$taxonomy}_relationships" ); 4215 4269 } 4216 4270
Note: See TracChangeset
for help on using the changeset viewer.