diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 935212652c55e..928d6513f9eaf 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -4892,7 +4892,7 @@ function is_object_in_term( $object_id, $taxonomy, $terms = null ) { return $object_terms; } - wp_cache_set( $object_id, wp_list_pluck( $object_terms, 'term_id' ), "{$taxonomy}_relationships" ); + wp_cache_add( $object_id, wp_list_pluck( $object_terms, 'term_id' ), "{$taxonomy}_relationships" ); } if ( is_wp_error( $object_terms ) ) { diff --git a/tests/phpunit/tests/term/isObjectInTerm.php b/tests/phpunit/tests/term/isObjectInTerm.php index fbaf7e17767c8..6bd04a453e78e 100644 --- a/tests/phpunit/tests/term/isObjectInTerm.php +++ b/tests/phpunit/tests/term/isObjectInTerm.php @@ -179,4 +179,32 @@ public function test_should_not_be_fooled_by_a_stale_relationship_cache() { public function test_invalid_taxonomy_should_return_wp_error_object() { $this->assertWPError( is_object_in_term( 12345, 'foo', 'bar' ) ); } + + /** + * @ticket 63618 + */ + public function test_term_objects_should_not_be_added_to_cache_when_suspend_cache_addition() { + register_taxonomy( 'wptests_tax', 'post' ); + + $t = self::factory()->term->create( + array( + 'taxonomy' => 'wptests_tax', + 'slug' => 'foo', + ) + ); + + $object_id = 12345; + wp_cache_delete( $object_id, 'wptests_tax_relationships' ); + + $suspend = wp_suspend_cache_addition(); + wp_suspend_cache_addition( true ); + + is_object_in_term( $object_id, 'wptests_tax', $t ); + + wp_suspend_cache_addition( $suspend ); + + $this->assertFalse( wp_cache_get( $object_id, 'wptests_tax_relationships' ) ); + + _unregister_taxonomy( 'wptests_tax', 'post' ); + } }