diff --git a/src/wp-includes/category-template.php b/src/wp-includes/category-template.php index 27b8bf221f..57f7cb9ada 100644 --- a/src/wp-includes/category-template.php +++ b/src/wp-includes/category-template.php @@ -232,6 +232,9 @@ function get_the_category_list( $separator = '', $parents='', $post_id = false ) * @return bool True if the current post is in any of the given categories. */ function in_category( $category, $post = null ) { + if ( empty( $category ) ) + return false; + return has_category( $category, $post ); } diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index c9c6ee6fcc..e94ad4c4f3 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -152,4 +152,20 @@ class Tests_Taxonomy extends WP_UnitTestCase { _unregister_post_type( $post_type ); } + /** + * @ticket 25706 + */ + function test_in_category() { + $post = $this->factory->post->create_and_get(); + + // in_category() returns false when first parameter is empty() + $this->assertFalse( in_category( '', $post ) ); + $this->assertFalse( in_category( false, $post ) ); + $this->assertFalse( in_category( null, $post ) ); + + // Test expected behavior of in_category() + $term = wp_insert_term( 'Test', 'category' ); + wp_set_object_terms( $post->ID, $term['term_id'], 'category' ); + $this->assertTrue( in_category( $term['term_id'], $post ) ); + } }