Ticket #36251: 36251.diff
File 36251.diff, 4.8 KB (added by , 9 years ago) |
---|
-
src/wp-includes/category-template.php
diff --git src/wp-includes/category-template.php src/wp-includes/category-template.php index 35d6c82..d0c8e02 100644
function get_the_terms( $post, $taxonomy ) { 1171 1171 if ( false === $terms ) { 1172 1172 $terms = wp_get_object_terms( $post->ID, $taxonomy ); 1173 1173 if ( ! is_wp_error( $terms ) ) { 1174 $to_cache = array(); 1175 foreach ( $terms as $key => $term ) { 1176 $to_cache[ $key ] = $term->data; 1177 } 1174 $to_cache = wp_list_pluck( $terms, 'term_id' ); 1178 1175 wp_cache_add( $post->ID, $to_cache, $taxonomy . '_relationships' ); 1179 1176 } 1180 1177 } -
src/wp-includes/taxonomy.php
diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php index 7bc2d40..86bec6e 100644
function wp_update_term( $term_id, $taxonomy, $args = array() ) { 3469 3469 */ 3470 3470 do_action( 'edited_term_taxonomy', $tt_id, $taxonomy ); 3471 3471 3472 // Clean the relationship caches for all object types using this term.3473 $objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) );3474 $tax_object = get_taxonomy( $taxonomy );3475 foreach ( $tax_object->object_type as $object_type ) {3476 clean_object_term_cache( $objects, $object_type );3477 }3478 3479 3472 /** 3480 3473 * Fires after a term has been updated, but before the term cache has been cleaned. 3481 3474 * … … function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { 3766 3759 * for `$taxonomy` and `$id`. 3767 3760 */ 3768 3761 function get_object_term_cache( $id, $taxonomy ) { 3769 return wp_cache_get( $id, "{$taxonomy}_relationships" ); 3762 $cached_ids = wp_cache_get( $id, "{$taxonomy}_relationships" ); 3763 3764 if ( false !== $cached_ids ) { 3765 $terms = array_map( 'get_term', $cached_ids ); 3766 3767 $term_data = array(); 3768 foreach ( $terms as $term ) { 3769 $term_data[] = $term->data; 3770 } 3771 return $term_data; 3772 } else { 3773 return $cached_ids; 3774 } 3770 3775 } 3771 3776 3772 3777 /** … … function update_object_term_cache($object_ids, $object_type) { 3816 3821 ) ); 3817 3822 3818 3823 $object_terms = array(); 3819 foreach ( (array) $terms as $term ) 3820 $object_terms[$term->object_id][$term->taxonomy][] = $term; 3824 foreach ( (array) $terms as $term ) { 3825 $object_terms[ $term->object_id ][ $term->taxonomy ][] = $term->term_id; 3826 } 3821 3827 3822 3828 foreach ( $ids as $id ) { 3823 3829 foreach ( $taxonomies as $taxonomy ) { … … function is_object_in_term( $object_id, $taxonomy, $terms = null ) { 4730 4736 $object_terms = get_object_term_cache( $object_id, $taxonomy ); 4731 4737 if ( false === $object_terms ) { 4732 4738 $object_terms = wp_get_object_terms( $object_id, $taxonomy, array( 'update_term_meta_cache' => false ) ); 4733 wp_cache_set( $object_id, $object_terms, "{$taxonomy}_relationships" ); 4739 $object_term_ids = wp_list_pluck( $object_terms, 'term_id' ); 4740 wp_cache_set( $object_id, $object_term_ids, "{$taxonomy}_relationships" ); 4734 4741 } 4735 4742 4736 4743 if ( is_wp_error( $object_terms ) ) -
tests/phpunit/tests/term/wpUpdateTerm.php
diff --git tests/phpunit/tests/term/wpUpdateTerm.php tests/phpunit/tests/term/wpUpdateTerm.php index 4d9d17b..b4c88a7 100644
class Tests_Term_WpUpdateTerm extends WP_UnitTestCase { 488 488 $this->assertInternalType( 'int', $found['term_taxonomy_id'] ); 489 489 } 490 490 491 public function test_wp_update_term_should_clean_object_term_cache() {492 register_taxonomy( 'wptests_tax_for_post', 'post' );493 register_taxonomy( 'wptests_tax_for_page', 'page' );494 $post = self::factory()->post->create();495 $page = self::factory()->post->create( array(496 'post_type' => 'page',497 ) );498 499 $t_for_post = self::factory()->term->create( array(500 'taxonomy' => 'wptests_tax_for_post',501 ) );502 $t_for_page = self::factory()->term->create( array(503 'taxonomy' => 'wptests_tax_for_page',504 ) );505 506 wp_set_post_terms( $post, array( $t_for_post ), 'wptests_tax_for_post' );507 wp_set_post_terms( $page, array( $t_for_page ), 'wptests_tax_for_page' );508 509 // Prime caches and verify.510 update_object_term_cache( array( $post ), 'post' );511 update_object_term_cache( array( $page ), 'page' );512 $this->assertNotEmpty( wp_cache_get( $post, 'wptests_tax_for_post_relationships' ) );513 $this->assertNotEmpty( wp_cache_get( $page, 'wptests_tax_for_page_relationships' ) );514 515 // Update a term in just one of the taxonomies.516 $found = wp_update_term( $t_for_post, 'wptests_tax_for_post', array(517 'slug' => 'foo',518 ) );519 520 // Only the relevant cache should have been cleared.521 $this->assertFalse( wp_cache_get( $post, 'wptests_tax_for_post_relationships' ) );522 $this->assertNotEmpty( wp_cache_get( $page, 'wptests_tax_for_page_relationships' ) );523 }524 525 491 public function test_wp_update_term_should_clean_term_cache() { 526 492 register_taxonomy( 'wptests_tax', 'post', array( 527 493 'hierarchical' => true,