Make WordPress Core

Opened 3 years ago

Last modified 3 months ago

#55358 new defect (bug)

Passing int term term_exists parent param not respected

Reported by: spacedmonkey's profile spacedmonkey Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: good-first-bug has-patch needs-testing
Focuses: Cc:

Description

If a developer calls terms_exists, with an int as term and parent as an int, the parent value is not respected. So example this will not work.

 $term = term_exists( 123, 'category', 1);

The code will check to see if term 123 exists, but will ignore parent value. This may result in correct / unexpected results.

Attachments (2)

55358.patch (704 bytes) - added by lgadzhev 2 years ago.
Adding $parent to the query when $term is used as an int
55358.1.patch (1.0 KB) - added by lgadzhev 2 years ago.
An optimized version that avoids duplicate code

Download all attachments as: .zip

Change History (8)

#1 @lopo
2 years ago

Looks more like a problem in the docs to me than an actual bug: if you give the ID as integer you don't need to restrict by parent; if you search by string, restricting by parent can definitely be helpful.

@lgadzhev
2 years ago

Adding $parent to the query when $term is used as an int

@lgadzhev
2 years ago

An optimized version that avoids duplicate code

#2 @lgadzhev
2 years ago

  • Keywords has-patch added; needs-patch needs-unit-tests removed

Hey, I've added a patch for that. Now it is going to include $parent in the query even when $term is int

#3 @JeffPaul
2 years ago

  • Keywords needs-testing added

#4 @spacedmonkey
7 months ago

  • Milestone changed from Awaiting Review to Future Release

@lgadzhev Thanks for your patch. Is it possible you could provide unit tests?

This ticket was mentioned in PR #6790 on WordPress/wordpress-develop by @thehercules.


3 months ago
#5

Fixes Ticket #55358

This PR addresses an issue in the term_exists function where the parent_term was not being respected when a term with an integer ID was passed along with a parent term ID. The function would only check if the term with the specified ID existed, ignoring the parent-child relationship.

Changes Made:

  • Updated the term_exists function to include the parent parameter in the query arguments when the term is an integer and a parent term ID is specified.
  • Added a condition to check for the presence of a parent term ID and include it in the query arguments.

#6 @thehercules
3 months ago

@spacedmonkey I have created a Patch https://github.com/WordPress/wordpress-develop/pull/6790. Could you review it and suggest changes if any.

Note: See TracTickets for help on using tickets.