#21426 closed enhancement (fixed)
Add get and set methods to WP_User_Query
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | Query | Version: | 3.1 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: |
Description
User queries are confusing to alter, so it would be helpful to have get and set methods a la WP_Query when altering WP_User_Query::query_vars in a filter or action.
do_action_ref_array( 'pre_user_query', array( &$this ) );
Without these methods, you have to do things like:
$query->query_vars[ 'meta_query' ] = array( $memory_hog );
Instead of:
$query->set( 'meta_query', array( $memory_hog ) );
Attachments (3)
Change History (14)
wonderboymusic
— 11 months ago
comment:3
nacin
— 10 months ago
One thing I don't like about WP_Query::get() is that it returns an empty string, rather than something like null or false. See #19243. It would be nice if we changed how WP_Query::get() works in the process.
comment:5
wonderboymusic
— 9 months ago
I like functions to return absolutely nothing in those cases, but you pick false / null if there's a consistency issue with WP_Query
comment:6
nacin
— 9 months ago
null would be the same as absolutely nothing, so that's fine. I may try to convert WP_Query::get() over to null in the future.
comment:7
nacin
— 9 months ago
- Keywords commit needs-unit-tests added
21426.diff — could use some basic unit tests.
comment:8
wonderboymusic
— 9 months ago
I am noticing this trend
wonderboymusic
— 9 months ago
comment:9
wonderboymusic
— 9 months ago
Attached tests - adds query.php to tests/user in Unit Tests
comment:10
nacin
— 9 months ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In [21995]:
I personally don't find WP_Query->set() and WP_Query->get() all that useful, but I do use them, so I don't know. +1 for consistency, I guess.