[wp-trac] [WordPress Trac] #61726: Not providing optional `$taxonomy` parameter in `get_edit_term_link()` leads to incorrect URL

WordPress Trac noreply at wordpress.org
Mon Jul 22 22:42:36 UTC 2024


#61726: Not providing optional `$taxonomy` parameter in `get_edit_term_link()`
leads to incorrect URL
-------------------------+-------------------------------------------------
 Reporter:  flixos90     |      Owner:  (none)
     Type:  defect       |     Status:  new
  (bug)                  |
 Priority:  normal       |  Milestone:  Future Release
Component:  Taxonomy     |    Version:  4.5
 Severity:  normal       |   Keywords:  needs-patch good-first-bug needs-
  Focuses:  template     |  unit-tests
-------------------------+-------------------------------------------------
 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 be
 `https://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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61726>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list