Opened 12 years ago
Closed 11 years ago
#21119 closed enhancement (fixed)
Make WP_User_Query::prepare_query() public
Reported by: | scribu | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Users | Keywords: | has-patch commit dev-reviewed |
Focuses: | Cc: |
Description
WP_User_Query tries to follow the pattern from WP_Query, where if you don't pass any args, it won't run the query.
The problem is that you can't do anything with that instance afterwards; both prepare_query() and query() accept no parameters.
Attachments (4)
Change History (15)
#2
@
11 years ago
- Component changed from General to Users
- Milestone changed from Awaiting Review to 3.9
Looks good.
#3
@
11 years ago
- Keywords needs-unit-tests added
21119.2.diff updates the patch, which was blowing up against trunk. I also made changes so that it passes all unit tests. This class is awkward, may need more unit tests.
#4
@
11 years ago
21119.3.diff adds unit tests for WP_User_Query::prepare_query()
and demonstrates how it works. It only does something if WP_User_Query::query_vars
is empty or an array of any options is passed. Otherwise, it rebuilds the object properties from the previously set query vars.
#5
@
11 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 27185:
#7
@
11 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
As noted in #27741, these unit tests fail under multisite. Multisite does indeed have a quirk here as it relates to WP_User_Query::prepare_query(), and I don't think it's the test that's the problem, but rather, this new public method.
The final $query->prepare_query() call re-does all of the logic in prepare_query(), re-adding another meta query for is_multisite(). This makes this function not safe to be called a second time, and I believe the intention was that it should.
[meta_query] => Array( [0] => Array( [key] => wptests_capabilities ) [1] => Array( [key] => wptests_capabilities ) )
On the bright side, this doesn't *appear* to break anything. We should just be able to just look for an existing duplicate meta query and discard adding a new one. Patch attached, 21119.4.diff. As it doesn't seem to break anything as-is, I could spin this into a new ticket for post-3.9 if necessary.
This ticket was mentioned in IRC in #wordpress-dev by nacin. View the logs.
11 years ago
#9
@
11 years ago
+1 for 21119.4.diff. It was an oversight in the initial patch.
With the patch, it's now possible to do this: