-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwp_user_query_wp_date_query_support.php
More file actions
48 lines (40 loc) · 1.28 KB
/
Copy pathwp_user_query_wp_date_query_support.php
File metadata and controls
48 lines (40 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Plugin Name: WP_User_Query-WP_Date_Query support
* Description: Adding Support for WP_Date_Query on column "user_registered" for WP_User_Query
* Plugin URI: http://marketpress.com/
* Version: 2013.11.14
* Author: MarketPress, Christian Brückner
* Author URI: http://marketpress.com/
* Licence: GPL 2
* License URI: http://opensource.org/licenses/GPL-2.0
*/
add_filter( 'date_query_valid_columns', 'marketpress_date_query_column_user_registered' );
/**
* Adding the column "user_registered" to WP_Date_Query
*
* @param Array $columns
* @return Array
*/
function marketpress_date_query_column_user_registered( $columns ) {
$columns[] = 'user_registered';
return $columns;
}
add_action( 'pre_user_query', 'marketpress_get_users_date_query' );
/**
* Adding the missing WP_Date_Query to WP_User_Query on "user_registered"
*
* @param WP_User_Query $user_query
* @internal WP_Date_Query
* @return WP_User_Query
*/
function marketpress_get_users_date_query( WP_User_Query $user_query ) {
if ( isset( $user_query->query_vars[ 'date_query' ] ) ) {
$date_query = new WP_Date_Query(
$user_query->query_vars[ 'date_query' ],
'user_registered'
);
$user_query->query_where .= ' ' . $date_query->get_sql();
}
return $user_query;
}