[wp-trac] [WordPress Trac] #63255: WP_Query normalization can break plugin filters comparing query variables.

WordPress Trac noreply at wordpress.org
Fri Apr 11 03:23:41 UTC 2025


#63255: WP_Query normalization can break plugin filters comparing query variables.
--------------------------------------+------------------------
 Reporter:  peterwilsoncc             |       Owner:  joemcgill
     Type:  defect (bug)              |      Status:  reviewing
 Priority:  normal                    |   Milestone:  6.8
Component:  Query                     |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------

Comment (by johnjamesjacoby):

 bbPress is an easy fix, and I'll get that done.

 I think the probability is high that other plugins are doing "loose"
 comparisons similar to bbPress for a few reasons:
 * all plugins get inspiration from each other, and thousands of them
 compare things to `WP_Query`
 * the order of array values in any `_Query` class has simply never
 mattered – it's totally off the radar of everyone
 * arrays of arguments are allowed to be out-of-order everywhere else (into
 and out-of functions & filters, etc...)

 Like @spacedmonkey said in the original ticket, all of the other `_Query`
 classes would benefit from the idea of normalizing the values that go into
 generating the cache key, so in that vein I think the most complete
 version of this code would include global public functions to encapsulate
 & DRY these (and other) specific repeated patterns:
 * `sort()`
 * `array_unique()`
 * `array_unique( array_map( 'absint', $thing ) ) `
 * `implode( ',', array_map( 'absint', $thing ) )`
 * `array_map( 'absint', array_unique( (array) $thing ) );`
 * `array_unique( array_map( 'intval', preg_split( '/[,\s]+/', $thing ) )
 );`

 If this were my call, me personally, I'd err on the side of avoiding
 breakage related to the infinite unknown of the plugin ecosystem, revert
 for 6.8, create some global functions for plugins (and core) to use, ship
 `WP_Query` in 6.8.1 or 6.8.2, and the other `_Query` classes subsequently.

 (Fwiw, I love this performance improvement overall, and already do
 something similar to this inside of BerlinDB, so I am excited to see it in
 WordPress too.)

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63255#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list