[wp-trac] [WordPress Trac] #45333: term_exists might fail if slugs are changed
WordPress Trac
noreply at wordpress.org
Mon Nov 12 22:28:06 UTC 2018
#45333: term_exists might fail if slugs are changed
--------------------------+-----------------------------
Reporter: leogermani | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
The steps to reproduce this are:
1. Create a term. For example: 'test 123'
2. Change its slug to something completely different. For example, from
'test-123' to 'something-else'
3. Now call the function `term_exists()` passing `'test 123'` (with 2
empty spaces between test and 123)
as the term name, along with the taxonomy.
You will notice that `term_exists()` will not find it.
However, if you try to add this same term, with the two spaces,
`wp_insert_term()` won't allow it because it will detect it as a
duplicate.
This issue I believe touches some bigger discussion around `term_exists()`
because this function handles the term name string in a different way that
`wp_insert_term()` does, which, in my opinion, creates an inconsistency.
I've seem some discussions around this on
[https://core.trac.wordpress.org/ticket/43345] and
[https://core.trac.wordpress.org/ticket/32248].
In [https://core.trac.wordpress.org/ticket/32248#comment:9 this comment],
@boonebgorges argues that "`term_exists()` is a low-level function.
Character encoding should be handled by the function that calls
`term_exists()`", but aknowledges the inconsistencies and says " In short:
it's a mess, and I don't recommend using it - use `get_term_by()`
instead."
In fact `get_term_by()` finds it.
So I guess the question is, shoud we touch term_exists() and make it find
the same duplicates wp_insert_term() does?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45333>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list