[wp-trac] [WordPress Trac] #58329: Double sanitization in get_term function
WordPress Trac
noreply at wordpress.org
Thu Sep 21 16:35:15 UTC 2023
#58329: Double sanitization in get_term function
-------------------------------------------------+-------------------------
Reporter: spacedmonkey | Owner:
| spacedmonkey
Type: enhancement | Status: closed
Priority: normal | Milestone: 6.4
Component: Taxonomy | Version:
Severity: normal | Resolution: fixed
Keywords: has-patch has-unit-tests dev- | Focuses:
feedback | performance
-------------------------------------------------+-------------------------
Changes (by spacedmonkey):
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"56650" 56650]:
{{{
#!CommitTicketReference repository="" revision="56650"
Taxonomy: Stop double sanitization in get_term function.
In the `get_term` function, the filter method is invoked on the `WP_Term`
object, which subsequently triggers the execution of `sanitize_term`. The
filter method is also executed within `WP_Term::get_instance`.
A common scenario when calling the `get_term` function is to invoke the
function with an integer ID for the term and a filter set to "raw." This
results in a call to `WP_Term::get_instance`. However, since both
`get_term` and `WP_Term::get_instance` invoke the filter method, it leads
to double sanitization of the term.
Considering that `get_term` may be called thousands of times on a page,
especially when priming a large number of terms into memory, this
redundancy can result in thousands of unnecessary calls to
`sanitize_term`. Performing the same sanitization operation twice with the
same parameters is wasteful and detrimental to performance.
To address this issue, the code has been updated to execute the filter
method only when the filter parameter does not match or when changes have
been made to the term object within the get_term hook. This optimization
ensures that the filter is applied selectively, mitigating performance
concerns and avoiding unnecessary sanitization calls.
Props spacedmonkey, flixos90, costdev, mukesh27, joemcgill, oglekler,
peterwilsoncc.
Fixes #58329.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58329#comment:22>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list