From 7b9e33a1e76c5052b57f7a701e5ec228b3751dea Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Fri, 26 Nov 2021 11:41:24 +0000 Subject: [PATCH] Taxonomy: Use `WP_Term` object to retrieve the taxonomy in `get_term_feed_link()`. This change fixes a backward compatibility issue introduced in [52180] where `get_term_feed_link()` did not honor the `$taxonomy` parameter anymore. Rather than using the default `category` taxonomy when passing a term ID in `get_term_feed_link()`, use the `WP_Term` object to get the taxonomy. Follow-up to [52180]. Props hugod. Fixes #50225. git-svn-id: https://develop.svn.wordpress.org/trunk@52255 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/link-template.php | 7 +++---- tests/phpunit/tests/term/getTermLink.php | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index d3316b0eab..6f44ccefe5 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -930,14 +930,13 @@ function get_category_feed_link( $cat, $feed = '' ) { */ function get_term_feed_link( $term, $taxonomy = '', $feed = '' ) { if ( ! is_object( $term ) ) { - $term = (int) $term; - $taxonomy = 'category'; - } elseif ( ! $term instanceof WP_Term ) { - $taxonomy = $term->taxonomy; + $term = (int) $term; } $term = get_term( $term, $taxonomy ); + $taxonomy = $term->taxonomy; + if ( empty( $term ) || is_wp_error( $term ) ) { return false; } diff --git a/tests/phpunit/tests/term/getTermLink.php b/tests/phpunit/tests/term/getTermLink.php index af41f9e92a..b9a396a4f6 100644 --- a/tests/phpunit/tests/term/getTermLink.php +++ b/tests/phpunit/tests/term/getTermLink.php @@ -265,6 +265,28 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase { get_term_link( get_term( $term, $taxonomy ), $taxonomy ); } + /** + * @dataProvider data_get_term_link + * + * @ticket 50225 + * + * @param string $taxonomy Taxonomy been tested (used for index of term keys). + * @param bool $use_id When true, pass term ID. Else, skip the test. + */ + public function test_get_term_feed_link_backward_compatibility( $taxonomy, $use_id ) { + if ( $use_id ) { + $term = $this->get_term( $taxonomy, $use_id ); + + $term_feed_link = get_term_feed_link( $term, $taxonomy ); + $this->assertIsString( $term_feed_link ); + + $term_feed_link = get_term_feed_link( $term, '' ); + $this->assertIsString( $term_feed_link ); + } else { + $this->markTestSkipped( 'This test requires to pass an id to get_term_feed_link()' ); + } + } + /** * Data provider. *