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.

Props stephenharris.
Fixes #34723.

git-svn-id: https://develop.svn.wordpress.org/trunk@35850 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-12-10 03:34:51 +00:00
parent ad338fb3d0
commit 52384c2e6b
2 changed files with 18 additions and 5 deletions

View File

@@ -627,4 +627,13 @@ class Tests_Term extends WP_UnitTestCase {
$cat_id2 = self::factory()->category->create( array( 'parent' => $cat_id1 ) );
$this->assertWPError( $cat_id2 );
}
/**
* @ticket 34723
*/
function test_get_the_terms_should_return_wp_error_when_taxonomy_is_unregistered() {
$p = self::$post_ids[0];
$terms = get_the_terms( $p, 'this-taxonomy-does-not-exist' );
$this->assertTrue( is_wp_error( $terms ) );
}
}