mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-26 06:13:07 +02:00
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. Built from https://develop.svn.wordpress.org/branches/4.4@35851 git-svn-id: http://core.svn.wordpress.org/branches/4.4@35815 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
92e15f6a8b
commit
9c18a6c284
@ -1148,14 +1148,18 @@ function get_the_terms( $post, $taxonomy ) {
|
|||||||
$terms = get_object_term_cache( $post->ID, $taxonomy );
|
$terms = get_object_term_cache( $post->ID, $taxonomy );
|
||||||
if ( false === $terms ) {
|
if ( false === $terms ) {
|
||||||
$terms = wp_get_object_terms( $post->ID, $taxonomy );
|
$terms = wp_get_object_terms( $post->ID, $taxonomy );
|
||||||
$to_cache = array();
|
if ( ! is_wp_error( $terms ) ) {
|
||||||
foreach ( $terms as $key => $term ) {
|
$to_cache = array();
|
||||||
$to_cache[ $key ] = $term->data;
|
foreach ( $terms as $key => $term ) {
|
||||||
|
$to_cache[ $key ] = $term->data;
|
||||||
|
}
|
||||||
|
wp_cache_add( $post->ID, $to_cache, $taxonomy . '_relationships' );
|
||||||
}
|
}
|
||||||
wp_cache_add( $post->ID, $to_cache, $taxonomy . '_relationships' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$terms = array_map( 'get_term', $terms );
|
if ( ! is_wp_error( $terms ) ) {
|
||||||
|
$terms = array_map( 'get_term', $terms );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the list of terms attached to the given post.
|
* Filter the list of terms attached to the given post.
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.4.1-alpha-35843';
|
$wp_version = '4.4.1-alpha-35851';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user