Support date_query by user_registered in WP_User_Query.

Props ChriCo, nacin.
Fixes #27283.
Built from https://develop.svn.wordpress.org/trunk@29934


git-svn-id: http://core.svn.wordpress.org/trunk@29686 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2014-10-17 01:37:18 +00:00
parent fcc82fd671
commit bde2c97aee
2 changed files with 13 additions and 2 deletions

View File

@ -451,7 +451,8 @@ class WP_Date_Query {
$valid_columns = array(
'post_date', 'post_date_gmt', 'post_modified',
'post_modified_gmt', 'comment_date', 'comment_date_gmt'
'post_modified_gmt', 'comment_date', 'comment_date_gmt',
'user_registered',
);
// Attempt to detect a table prefix.
@ -463,7 +464,8 @@ class WP_Date_Query {
*
* @param array $valid_columns An array of valid date query columns. Defaults
* are 'post_date', 'post_date_gmt', 'post_modified',
* 'post_modified_gmt', 'comment_date', 'comment_date_gmt'
* 'post_modified_gmt', 'comment_date', 'comment_date_gmt',
* 'user_registered'
*/
if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ) ) ) {
$column = 'post_date';
@ -480,6 +482,9 @@ class WP_Date_Query {
'comment_date',
'comment_date_gmt',
),
$wpdb->users => array(
'user_registered',
),
);
// If it's a known column name, add the appropriate table prefix.

View File

@ -742,6 +742,12 @@ class WP_User_Query {
$this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)";
}
// Date queries are allowed for the user_registered field.
if ( ! empty( $qv['date_query'] ) && is_array( $qv['date_query'] ) ) {
$date_query = new WP_Date_Query( $qv['date_query'], 'user_registered' );
$this->query_where .= $date_query->get_sql();
}
/**
* Fires after the WP_User_Query has been parsed, and before
* the query is executed.