diff --git a/src/wp-includes/category-template.php b/src/wp-includes/category-template.php index f2ed10895c..671d9bfeae 100644 --- a/src/wp-includes/category-template.php +++ b/src/wp-includes/category-template.php @@ -1200,20 +1200,19 @@ function tag_description( $tag = 0 ) { * Retrieve term description. * * @since 2.8.0 + * @since 4.9.2 The `$taxonomy` parameter was deprecated. * * @param int $term Optional. Term ID. Will use global term ID by default. - * @param string $taxonomy Optional taxonomy name. Defaults to 'post_tag'. * @return string Term description, available. */ -function term_description( $term = 0, $taxonomy = 'post_tag' ) { +function term_description( $term = 0 ) { if ( ! $term && ( is_tax() || is_tag() || is_category() ) ) { $term = get_queried_object(); if ( $term ) { - $taxonomy = $term->taxonomy; - $term = $term->term_id; + $term = $term->term_id; } } - $description = get_term_field( 'description', $term, $taxonomy ); + $description = get_term_field( 'description', $term ); return is_wp_error( $description ) ? '' : $description; } diff --git a/tests/phpunit/tests/category/categoryDescription.php b/tests/phpunit/tests/category/categoryDescription.php new file mode 100644 index 0000000000..f54c65bb0d --- /dev/null +++ b/tests/phpunit/tests/category/categoryDescription.php @@ -0,0 +1,78 @@ +category->create( array( + 'description' => $description, + ) ); + + $found = category_description( $c ); + $expected = apply_filters( 'term_description', $description ); + + $this->assertSame( $expected, $found ); + } + + public function test_success_query_by_object() { + $description = 'Foo'; + $c = self::factory()->category->create( array( + 'description' => $description, + 'slug' => 'bar', + ) ); + + $category = get_term( $c ); + + $found = category_description( $c ); + $expected = apply_filters( 'term_description', $description ); + + $this->assertSame( $expected, $found ); + } + + /** + * @ticket 42605 + * @ticket 42771 + */ + public function test_should_return_description_for_term_from_another_taxonomy_on_primed_cache() { + register_taxonomy( 'wptests_tax', 'post' ); + + $description = 'Foo'; + + $t = self::factory()->term->create( array( + 'taxonomy' => 'wptests_tax', + 'description' => $description, + ) ); + + $term = get_term( $t ); + + $found = category_description( $t ); + $expected = apply_filters( 'term_description', $description ); + + $this->assertSame( $expected, $found ); + } + + /** + * @ticket 42605 + * @ticket 42771 + */ + public function test_should_return_description_for_term_from_another_taxonomy_on_empty_cache() { + register_taxonomy( 'wptests_tax', 'post' ); + + $description = 'Foo'; + + $t = self::factory()->term->create( array( + 'taxonomy' => 'wptests_tax', + 'description' => $description, + ) ); + + clean_term_cache( $t ); + + $found = category_description( $t ); + $expected = apply_filters( 'term_description', $description ); + + $this->assertSame( $expected, $found ); + } +}