From e9d828ce41f16fea14aec0478d6db7bb19a16c39 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 4 Dec 2017 20:38:57 +0000 Subject: [PATCH] Don't do a strict taxonomy check in `get_category_link()`. Prior to version 4.9, a quirk in the implementation of `get_term()` caused `get_category_link( 123 )` to fetch the taxonomy archive link for term 123 even if 123 is not in the 'category' taxonomy. The quirk was fixed in [40979]; see #40671. This bugfix introduced a regression for theme authors who were expecting the old behavior. By lifting the 'category' restriction, we allow the template function to work in the old way. Fixes #42717. See #42771. git-svn-id: https://develop.svn.wordpress.org/trunk@42364 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/category-template.php | 2 +- .../tests/category/getCategoryLink.php | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/tests/category/getCategoryLink.php diff --git a/src/wp-includes/category-template.php b/src/wp-includes/category-template.php index c3782441e6..77c0d4532a 100644 --- a/src/wp-includes/category-template.php +++ b/src/wp-includes/category-template.php @@ -21,7 +21,7 @@ function get_category_link( $category ) { $category = (int) $category; } - $category = get_term_link( $category, 'category' ); + $category = get_term_link( $category ); if ( is_wp_error( $category ) ) { return ''; diff --git a/tests/phpunit/tests/category/getCategoryLink.php b/tests/phpunit/tests/category/getCategoryLink.php new file mode 100644 index 0000000000..49115ac608 --- /dev/null +++ b/tests/phpunit/tests/category/getCategoryLink.php @@ -0,0 +1,54 @@ +category->create(); + + $found = get_category_link( $c ); + $expected = home_url( '?cat=' . $c ); + + $this->assertSame( $expected, $found ); + } + + /** + * @ticket 42771 + */ + public function test_should_return_link_for_term_from_another_category_on_primed_cache() { + register_taxonomy( 'wptests_tax', 'post' ); + + $t = self::factory()->term->create( array( + 'taxonomy' => 'wptests_tax', + 'slug' => 'test-term', + ) ); + + $term = get_term( $t ); + + $found = get_category_link( $t ); + $expected = home_url( '?wptests_tax=test-term' ); + + $this->assertSame( $expected, $found ); + } + + /** + * @ticket 42771 + */ + public function test_should_return_link_for_term_from_another_category_on_empty_cache() { + register_taxonomy( 'wptests_tax', 'post' ); + + $t = self::factory()->term->create( array( + 'taxonomy' => 'wptests_tax', + 'slug' => 'test-term', + ) ); + + clean_term_cache( $t ); + + $found = get_category_link( $t ); + $expected = home_url( '?wptests_tax=test-term' ); + + $this->assertSame( $expected, $found ); + } +}