[wp-trac] [WordPress Trac] #47099: term_exists fail when term is surrounded with brackets
WordPress Trac
noreply at wordpress.org
Fri May 10 15:06:04 UTC 2019
#47099: term_exists fail when term is surrounded with brackets
-------------------------------------+------------------------------
Reporter: leogermani | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version:
Severity: normal | Resolution:
Keywords: close reporter-feedback | Focuses:
-------------------------------------+------------------------------
Changes (by boonebgorges):
* keywords: => close reporter-feedback
Comment:
The issue is that `term_exists()` doesn't know whether you're passing in a
`slug` or a `name`. When it does a `slug` check, the value is passed
through `sanitize_title()`. This "sanitizes" `[test]` to `test`.
One way to address the problem is for you to be able to specify whether
`[test]` is intended as a `slug` or a `name`. This is called
`get_term_by()` :) As I've noted previously, my recommendation is to use
this function instead.
If we were to change the behavior of `term_exists()`, it'd presumably be
something along the lines of: when the `$term` passed to the function
contains characters that'd normally be stripped by `sanitize_title()`,
skip the `slug` check (or modify it somehow, or something like that). But
any change of this sort is highly likely to break someone's existing code
that depends on the existing idiosyncracies of `term_exists()`.
Given that we have a viable alternative in `get_term_by()`, I don't see
the benefit of risking these compatibility breaks.
It's possible that there's a technical strategy for addressing the issue
that would *not* break compatibility (though it's hard for me to see what
it'd be, since you are, in fact, suggesting a behavior change!). If you've
got concrete ideas, please feel free to pitch them. But note that, in my
opinion, a "fix" for this longstanding behavior that breaks existing
plugins is probably not going to be viable.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47099#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list