diff --git a/src/wp-includes/category-template.php b/src/wp-includes/category-template.php index 77c0d4532a..27061e7266 100644 --- a/src/wp-includes/category-template.php +++ b/src/wp-includes/category-template.php @@ -1111,17 +1111,7 @@ function walk_category_dropdown_tree() { * @return string Link on success, empty string if tag does not exist. */ function get_tag_link( $tag ) { - if ( ! is_object( $tag ) ) { - $tag = (int) $tag; - } - - $tag = get_term_link( $tag, 'post_tag' ); - - if ( is_wp_error( $tag ) ) { - return ''; - } - - return $tag; + return get_category_link( $tag ); } /** diff --git a/tests/phpunit/tests/term/getTagLink.php b/tests/phpunit/tests/term/getTagLink.php new file mode 100644 index 0000000000..5b28c1d5dc --- /dev/null +++ b/tests/phpunit/tests/term/getTagLink.php @@ -0,0 +1,57 @@ +term->create( array( + 'taxonomy' => 'post_tag', + 'slug' => 'term-slug', + ) ); + + $found = get_tag_link( $t ); + $expected = home_url( '?tag=term-slug' ); + + $this->assertSame( $expected, $found ); + } + + /** + * @ticket 42771 + */ + public function test_should_return_link_for_term_from_another_taxonomy_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_tag_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_taxonomy_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_tag_link( $t ); + $expected = home_url( '?wptests_tax=test-term' ); + + $this->assertSame( $expected, $found ); + } +}