From 8951af66d48ac25c286e132eeb5b9b078be4ee7b Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 4 Dec 2017 20:51:27 +0000 Subject: [PATCH] Fix regression in `get_tag_link()` since 4.9. See [42364] for description of the problem. Because `get_category_link()` is now totally taxonomy-agnostic, `get_tag_link()` can become a simple wrapper. Props juiiee8487, markjaquith. See #42771. git-svn-id: https://develop.svn.wordpress.org/trunk@42366 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/category-template.php | 12 +----- tests/phpunit/tests/term/getTagLink.php | 57 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 tests/phpunit/tests/term/getTagLink.php 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 ); + } +}