diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
index 12efa5a..a1de09f 100644
|
|
function get_object_term_cache( $id, $taxonomy ) { |
3038 | 3038 | |
3039 | 3039 | $terms = array(); |
3040 | 3040 | foreach ( $term_ids as $term_id ) { |
3041 | | $terms[] = wp_cache_get( $term_id, 'terms' ); |
| 3041 | $term = get_term( $term_id ); |
| 3042 | if ( is_wp_error( $term ) ) { |
| 3043 | return $term; |
| 3044 | } |
| 3045 | |
| 3046 | $terms[] = $term; |
3042 | 3047 | } |
3043 | 3048 | |
3044 | | return array_map( 'get_term', $terms ); |
| 3049 | return $terms; |
3045 | 3050 | } |
3046 | 3051 | |
3047 | 3052 | /** |
diff --git tests/phpunit/tests/term/cache.php tests/phpunit/tests/term/cache.php
index 1ce755b..fb7a5a8 100644
|
|
class Tests_Term_Cache extends WP_UnitTestCase { |
390 | 390 | $this->assertSame( $term_meta, 'bar' ); |
391 | 391 | $this->assertEquals( $num_queries, $wpdb->num_queries ); |
392 | 392 | } |
| 393 | |
| 394 | /** |
| 395 | * @ticket 37291 |
| 396 | */ |
| 397 | public function test_get_object_term_cache_should_return_error_if_any_term_is_an_error() { |
| 398 | register_taxonomy( 'wptests_tax', 'post' ); |
| 399 | |
| 400 | $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); |
| 401 | $p = self::factory()->post->create(); |
| 402 | wp_set_object_terms( $p, $t, 'wptests_tax' ); |
| 403 | |
| 404 | // Prime cache. |
| 405 | $terms = get_the_terms( $p, 'wptests_tax' ); |
| 406 | $this->assertEqualSets( array( $t ), wp_list_pluck( $terms, 'term_id' ) ); |
| 407 | |
| 408 | /* |
| 409 | * Modify cached array to insert an empty term ID, |
| 410 | * which will trigger an error in get_term(). |
| 411 | */ |
| 412 | $cached_ids = wp_cache_get( $p, 'wptests_tax_relationships' ); |
| 413 | $cached_ids[] = 0; |
| 414 | wp_cache_set( $p, $cached_ids, 'wptests_tax_relationships' ); |
| 415 | |
| 416 | $terms = get_the_terms( $p, 'wptests_tax' ); |
| 417 | $this->assertWPError( $terms ); |
| 418 | } |
393 | 419 | } |