Changeset 38776
- Timestamp:
- 10/11/2016 01:55:58 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r38747 r38776 3011 3011 * 3012 3012 * @since 2.3.0 3013 * @since 4.6.2 Returns a WP_Error object if get_term() returns an error for 3014 * any of the matched terms. 3013 3015 * 3014 3016 * @param int $id Term object ID. 3015 3017 * @param string $taxonomy Taxonomy name. 3016 * @return bool|array Array of `WP_Term` objects, if cached False if cache is empty for `$taxonomy` and `$id`. 3018 * @return bool|array|WP_Error Array of `WP_Term` objects, if cached. 3019 * False if cache is empty for `$taxonomy` and `$id`. 3020 * WP_Error if get_term() returns an error object for any term. 3017 3021 */ 3018 3022 function get_object_term_cache( $id, $taxonomy ) { … … 3039 3043 $terms = array(); 3040 3044 foreach ( $term_ids as $term_id ) { 3041 $terms[] = wp_cache_get( $term_id, 'terms' ); 3042 } 3043 3044 return array_map( 'get_term', $terms ); 3045 $term = get_term( $term_id ); 3046 if ( is_wp_error( $term ) ) { 3047 return $term; 3048 } 3049 3050 $terms[] = $term; 3051 } 3052 3053 return $terms; 3045 3054 } 3046 3055 -
trunk/tests/phpunit/tests/term/cache.php
r38677 r38776 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 }
Note: See TracChangeset
for help on using the changeset viewer.