From 83c7544ef8d3e9222306fade9ec076d03844d63f Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 18 Aug 2016 19:14:52 +0000 Subject: [PATCH] In `is_object_in_term()`, return error object rather than caching it. This change prevents an error object from being stored in the cache, and prevents notices from being thrown when plucking term IDs to put into the relationship cache. See #32044, #36814. Props rpayne7264. Fixes #37721. git-svn-id: https://develop.svn.wordpress.org/trunk@38277 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/taxonomy.php | 4 ++++ tests/phpunit/tests/term/isObjectInTerm.php | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 104a4afdb5..70af35a326 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -4274,6 +4274,10 @@ function is_object_in_term( $object_id, $taxonomy, $terms = null ) { $object_terms = get_object_term_cache( $object_id, $taxonomy ); if ( false === $object_terms ) { $object_terms = wp_get_object_terms( $object_id, $taxonomy, array( 'update_term_meta_cache' => false ) ); + if ( is_wp_error( $object_terms ) ) { + return $object_terms; + } + wp_cache_set( $object_id, wp_list_pluck( $object_terms, 'term_id' ), "{$taxonomy}_relationships" ); } diff --git a/tests/phpunit/tests/term/isObjectInTerm.php b/tests/phpunit/tests/term/isObjectInTerm.php index 0da95ab9fd..ed054f8ea3 100644 --- a/tests/phpunit/tests/term/isObjectInTerm.php +++ b/tests/phpunit/tests/term/isObjectInTerm.php @@ -146,4 +146,11 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase { $num_queries++; $this->assertSame( $num_queries, $wpdb->num_queries ); } + + /** + * @ticket 37721 + */ + public function test_invalid_taxonomy_should_return_wp_error_object() { + $this->assertWPError( is_object_in_term( 12345, 'foo', 'bar' ) ); + } }