Make WordPress Core

Ticket #27283: 27283.diff

File 27283.diff, 3.0 KB (added by nacin, 11 years ago)
  • src/wp-includes/date.php

     
    167167        public function validate_column( $column ) {
    168168                $valid_columns = array(
    169169                        'post_date', 'post_date_gmt', 'post_modified',
    170                         'post_modified_gmt', 'comment_date', 'comment_date_gmt'
     170                        'post_modified_gmt', 'comment_date', 'comment_date_gmt',
     171                        'user_registered',
    171172                );
    172173                /**
    173174                 * Filter the list of valid date query columns.
     
    175176                 * @since 3.7.0
    176177                 *
    177178                 * @param array $valid_columns An array of valid date query columns. Defaults are 'post_date', 'post_date_gmt',
    178                  *                             'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt'
     179                 *                             'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt',
     180                 *                             'user_registered'
    179181                 */
    180182                if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ) ) )
    181183                        $column = 'post_date';
  • src/wp-includes/user.php

     
    690690                        $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)";
    691691                }
    692692
     693                // Date queries are allowed for the user_registered field.
     694                if ( ! empty( $qv['date_query'] ) && is_array( $qv['date_query'] ) ) {
     695                        $date_query = new WP_Date_Query( $qv['date_query'], 'user_registered' );
     696                        $this->query_where .= $date_query->get_sql();
     697                }
     698
    693699                /**
    694700                 * Fires after the WP_User_Query has been parsed, and before
    695701                 * the query is executed.
  • tests/phpunit/tests/user.php

     
    66 */
    77class Tests_User extends WP_UnitTestCase {
    88
     9        function test_get_user_by_user_registered() {
     10
     11                $date_query_test_args = array();
     12
     13                // users registered last 30 days
     14                $date_query_test_args[] = array(
     15                        'after' => '-30 days'
     16                );
     17
     18                // users registered in current month
     19                $date_query_test_args[] = array(
     20                        'month' => gmdate( 'n' )
     21                );
     22
     23                // users registered dayofweek between 2 and 6 AND before 01.01.2014
     24                $date_query_test_args[] = array(
     25                        array(
     26                                'dayofweek' => array( 2, 6 ),
     27                                'compare'   => 'BETWEEN',
     28                        ),
     29                        array(
     30                                'before'    => 'January 1st, 2014'
     31                        ),
     32                        'relation' => 'AND'
     33                );
     34
     35                foreach ( $date_query_test_args as $query_test_arg ) {
     36
     37                        $user = new WP_User_Query( array(
     38                                'date_query' => $query_test_arg
     39                        ) );
     40
     41                        // creating a date_query-object to compare the WP_User_Query-Where with the WP_Date_Query-Date
     42                        $date_query = new WP_Date_Query( $query_test_arg, 'user_registered' );
     43                        $this->assertEquals( $user->query_where, 'WHERE 1=1' . $date_query->get_sql() );
     44
     45                }
     46
     47        }
     48
    949        function test_get_users_of_blog() {
    1050                // add one of each user role
    1151                $nusers = array();