Opened 10 years ago
Last modified 7 weeks ago
#35913 new defect (bug)
`is_()` conditional methods should share their logic
| Reported by: | | Owned by: | |
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Query | Keywords: | has-patch 2nd-opinion needs-testing |
| Focuses: | Cc: |
Description
Many of the is_() methods in WP_Query share the nearly the exact same logic. As such, they share the exact same bugs, and fixing those bugs requires many parallel changes and huge numbers of tests. See #35902 and #24674 for some recent examples.
It's possible to move all the shared logic to a single protected utility method. It's a bit more abstract, but is much easier to maintain and test.
Attachments (2)
Change History (10)
#3
@
6 months ago
- Keywords needs-refresh added
- Milestone changed from Future Release to 6.9
I like the red!
I concur!
This patch doesn't apply clean since WP_Query is now in a different file though. Would love to see if it's still possible for this duplicate code to be removed in 6.9.
This ticket was mentioned in PR #9161 on WordPress/wordpress-develop by @sukhendu2002.
6 months ago #4
- Keywords needs-refresh removed
Trac ticket: https://core.trac.wordpress.org/ticket/35913
#5
@
5 months ago
Refactor: Introduce shared helper for is_*() conditional methods to reduce code duplication in WP_Query
#6
@
7 weeks ago
- Keywords needs-testing added
I think this needs to be punted. The current PR hasn't been reviewed/tested.
35913.diff demonstrates how it can be done. (Look at all that red! <3)
The one slight functional change from the current behavior, made to simplify the new
is_object_type(), is that *all*$objectproperties are cast to strings before thein_array()checks, instead of just the numerical ones. This will be redundant, since all of these properties are already strings.Anyone have thoughts about the wisdom, or lack thereof, of this kind of abstraction?