Make WordPress Core

Opened 2 years ago

Last modified 3 weeks 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 23 months ago.
Adding $parent to the query when $term is used as an int
55358.1.patch (1.0 KB) - added by lgadzhev 23 months ago.
An optimized version that avoids duplicate code

Download all attachments as: .zip

Change History (6)

#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
23 months ago

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

@lgadzhev
23 months ago

An optimized version that avoids duplicate code

#2 @lgadzhev
23 months 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
17 months ago

  • Keywords needs-testing added

#4 @spacedmonkey
3 weeks ago

  • Milestone changed from Awaiting Review to Future Release

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

Note: See TracTickets for help on using tickets.