Make WordPress Core


Ignore:
Timestamp:
12/10/2015 03:43:50 AM (9 years ago)
Author:
boonebgorges
Message:

Improve handling for WP_Error objects in get_the_terms().

wp_get_object_terms() can return a WP_Error object. As such, the
get_the_terms() cache wrapper should handle them properly. To wit:

  • Don't try to map an error object to get_term(). Introduced in [35032].
  • Don't cache an error object as taxonomy relationships. Introduced in at least [16487], maybe earlier.

Ports [35850] to the 4.4 branch.

Props stephenharris.
Fixes #34723.

Location:
branches/4.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

  • branches/4.4/src/wp-includes/category-template.php

    r35293 r35851  
    11491149    if ( false === $terms ) {
    11501150        $terms = wp_get_object_terms( $post->ID, $taxonomy );
    1151         $to_cache = array();
    1152         foreach ( $terms as $key => $term ) {
    1153             $to_cache[ $key ] = $term->data;
    1154         }
    1155         wp_cache_add( $post->ID, $to_cache, $taxonomy . '_relationships' );
    1156     }
    1157 
    1158     $terms = array_map( 'get_term', $terms );
     1151        if ( ! is_wp_error( $terms ) ) {
     1152            $to_cache = array();
     1153            foreach ( $terms as $key => $term ) {
     1154                $to_cache[ $key ] = $term->data;
     1155            }
     1156            wp_cache_add( $post->ID, $to_cache, $taxonomy . '_relationships' );
     1157        }
     1158    }
     1159
     1160    if ( ! is_wp_error( $terms ) ) {
     1161        $terms = array_map( 'get_term', $terms );
     1162    }
    11591163
    11601164    /**
Note: See TracChangeset for help on using the changeset viewer.