Make WordPress Core

Ticket #27283: #27283.patch

File #27283.patch, 3.6 KB (added by ChriCo, 11 years ago)

Added patch with unit-tests

  • tests/phpunit/tests/user.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    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();
  • src/wp-includes/user.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    455455                                'meta_key' => '',
    456456                                'meta_value' => '',
    457457                                'meta_compare' => '',
     458                                'date_query' => '',
    458459                                'include' => array(),
    459460                                'exclude' => array(),
    460461                                'search' => '',
     
    632633                } elseif ( ! empty( $qv['exclude'] ) ) {
    633634                        $ids = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
    634635                        $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)";
     636                }
     637
     638                // adding the date_query-Search for user_registered
     639                if ( !empty( $qv[ 'date_query' ] ) ) {
     640
     641                        $date_query = new WP_Date_Query(
     642                                $qv[ 'date_query' ],
     643                                'user_registered'
     644                        );
     645                        $this->query_where .= $date_query->get_sql();
     646
    635647                }
    636648
    637649                /**
     
    19962008        wp_new_user_notification( $user_id, $user_pass );
    19972009
    19982010        return $user_id;
    1999 }
     2011}
     2012 No newline at end of file
  • src/wp-includes/date.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    164164        public function validate_column( $column ) {
    165165                $valid_columns = array(
    166166                        'post_date', 'post_date_gmt', 'post_modified',
    167                         'post_modified_gmt', 'comment_date', 'comment_date_gmt'
     167                        'post_modified_gmt', 'comment_date', 'comment_date_gmt',
     168                    'user_registered'
    168169                );
    169170                /**
    170171                 * Filter the list of valid date query columns.
     
    172173                 * @since 3.7.0
    173174                 *
    174175                 * @param array $valid_columns An array of valid date query columns. Defaults are 'post_date', 'post_date_gmt',
    175                  *                             'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt'
     176                 *                             'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt', 'user_registered'
    176177                 */
    177178                if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ) ) )
    178179                        $column = 'post_date';