#61726 closed defect (bug) (fixed)
Not providing optional `$taxonomy` parameter in `get_edit_term_link()` leads to incorrect URL
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | 4.5 |
Component: | Taxonomy | Keywords: | good-first-bug has-patch has-unit-tests |
Focuses: | template | Cc: |
Description
In #35922, the $taxonomy
parameter of get_edit_term_link()
was made optional, as part of a greater effort to automatically determine the correct taxonomy for the given term. See also [36646] and follow-up [36986].
However, with that function it appears there was an oversight in that change, as the not providing the parameter leads to an incorrect URL returned: While in one place the function gets the taxonomy from the term object in a $tax
variable, in another place the function still uses the originally passed $taxonomy
parameter, which leads to this bug.
Despite being present for many years now, this bug probably hasn't been spotted because get_edit_term_link()
isn't used much directly, as the edit_term_link()
function is usually used. Since the function still passes the correct $taxonomy
parameter to get_edit_term_link()
, there's no problem in that situation. But calling get_edit_term_link()
without a $taxonomy
parameter leads to the incorrect URL.
To illustrate the bug with an example:
- Let's say there's a category with ID 42.
- Call
get_edit_term_link( 42 )
. - The result will be
https://example.org/wp-admin/term.php?tag_ID=42&post_type=post
. But it should behttps://example.org/wp-admin/term.php?taxonomy=category&tag_ID=42&post_type=post
. - Accessing the incorrect URL will in most scenarios lead to an error screen, because the
taxonomy
query parameter is missing.
The fix should be rather straightforward: Instead of using $taxonomy
to populate the taxonomy
query parameter, we need to use $tax
, which always contains the correct taxonomy.
A test should also be added to verify the bug is fixed.
Change History (7)
This ticket was mentioned in PR #7070 on WordPress/wordpress-develop by @debarghyabanerjee.
9 months ago
#2
- Keywords has-patch added; needs-patch removed
Trac Ticket: Core-61726
## Problem
- The get_edit_term_link() function currently generates an incorrect URL when the $taxonomy parameter is omitted. This issue arises because $taxonomy was made optional, aiming to automatically determine the correct taxonomy from the term object ($tax). However, the implementation overlooked consistently using $tax->name to populate the taxonomy query parameter in all scenarios.
## Solution
- To resolve this issue, we have updated get_edit_term_link() to consistently use $tax->name instead of $taxonomy when generating the URL. This ensures that the correct taxonomy name is always included in the URL structure, preventing errors and inconsistencies.
## Steps to Reproduce
- Call get_edit_term_link( 42 ) where 42 is the ID of a term.
-Without the fix, observe that the generated URL lacks the taxonomy parameter, leading to incorrect behavior.
## Changes Made
- Modified get_edit_term_link() to use $tax->name for populating the taxonomy query parameter.
## Testing
- Tested the fix by invoking get_edit_term_link() with and without the $taxonomy parameter.
- Verified that the URL structure is correct in both cases and no errors occur.
- This enhancement ensures consistent behavior in get_edit_term_link() when determining the correct taxonomy for generating term edit URLs.
#4
@
9 months ago
- Milestone changed from Future Release to 6.7
- Owner set to flixos90
- Status changed from new to reviewing
@debarghyabanerjee commented on PR #7070:
9 months ago
#5
Hi @felixarntz , Thanks you for the feedback, I have addressed them and made the necessary changes, assigning you again for re-review.
@flixos90 commented on PR #7070:
9 months ago
#7
Committed in https://core.trac.wordpress.org/changeset/58807
cc @boonebgorges for visibility