Opened 14 years ago
Closed 12 years ago
#21119 closed enhancement (fixed)
Make WP_User_Query::prepare_query() public
| Reported by: | scribu | Owned by: | wonderboymusic |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.9 |
| Component: | Users | Version: | |
| Severity: | normal | Keywords: | has-patch commit dev-reviewed |
| Cc: | Focuses: |
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)
#3
@
13 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
@
13 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.
#7
@
12 years ago
- Resolution fixed
- Status closed → 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.
12 years ago
#9
@
12 years ago
+1 for 21119.4.diff. It was an oversight in the initial patch.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
With the patch, it's now possible to do this: