Make WordPress Core

Ticket #25552: 25552.5.diff

File 25552.5.diff, 7.3 KB (added by DrewAPicture, 12 years ago)
  • src/wp-includes/date.php

     
    22/**
    33 * WP_Date_Query will generate a MySQL WHERE clause for the specified date-based parameters.
    44 *
    5  * Initialize the class by passing an array of arrays of parameters. Example:
    6  *
    7  * $date_query = new WP_Date_Query( array(
    8  *              'column' => 'optional, column to query against, default is post_date',
    9  *              'compare' => 'optional, see WP_Date_Query::get_compare()',
    10  *              'relation' => 'optional, OR or AND, how the sub-arrays should be compared, default is AND',
    11  *              array(
    12  *                      'column' => 'see above',
    13  *                      'compare' => 'see above',
    14  *                      'after' => 'string or array, see WP_Date_Query::build_mysql_datetime()',
    15  *                      'before' => 'string or array, see WP_Date_Query::build_mysql_datetime()',
    16  *                      'inclusive' => 'boolean, for after/before, whether exact value should be matched or not',
    17  *                      'year' => '4 digit int',
    18  *                      'month' => 'int, 1-12',
    19  *                      'week' => 'int, 0-53',
    20  *                      'day' => 'int, 1-31',
    21  *                      'hour' => 'int, 0-23',
    22  *                      'minute' => 'int, 0-60',
    23  *                      'second' => 'int, 0-60',
    24  *              ),
    25  *              array(
    26  *                      ...
    27  *              ),
    28  *              ...
    29  * ) );
    30  *
    31  * Then call the get_sql() method to get the MySQL WHERE string:
    32  *
    33  * $where .= $date_query->get_sql();
    34  *
     5 * Initialize the class by passing an array of arrays of parameters.
     6 *
    357 * @link http://codex.wordpress.org/Function_Reference/WP_Query Codex page.
    368 *
    379 * @since 3.7.0
     
    7446        public $compare = '=';
    7547
    7648        /**
    77          * Constructor
     49         * Constructor.
    7850         *
    79          * @param array $date_query A date query parameter array, see class descriptor for further details.
    80          * @param array (optional) $default_column What column name to query against. Defaults to "post_date".
     51         * @param array $date_query {
     52         *     One or more associative arrays of date query parameters.
     53         *
     54         *     @type array {
     55         *         @type string $column   Optional. The column to query against. If undefined, inherits the value of
     56         *                                the $default_column parameter. Default 'post_date'. Accepts 'post_date',
     57         *                                'post_date_gmt', 'post_modified','post_modified_gmt', 'comment_date',
     58         *                                'comment_date_gmt'.
     59         *         @type string $compare  Optional. The comparison operator.
     60         *                                Default '='. Accepts '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN',
     61         *                                'BETWEEN', 'NOT BETWEEN'.
     62         *         @type string $relation Optional. The boolean relationship between the date queryies.
     63         *                                Default 'OR'. Accepts 'OR', 'AND'.
     64         *         @type array {
     65         *             @type string|array $before Optional. Date to retrieve posts before. Accepts strtotime()-compatible
     66         *                                        string, or array of 'year', 'month', 'day' values. {
     67         *
     68         *                 @type string $year  The four-digit year. Default empty. Accepts any four-digit year.
     69         *                 @type string $month Optional when passing array.The month of the year.
     70         *                                     Default (string:empty)|(array:1). Accepts numbers 1-12.
     71         *                 @type string $day   Optional when passing array.The day of the month.
     72         *                                     Default (string:empty)|(array:1). Accepts numbers 1-31.
     73         *             }
     74         *             @type string|array $after Optional. Date to retrieve posts before. Accepts strtotime()-compatible
     75         *                                       string, or array of 'year', 'month', 'day' values. {
     76         *
     77         *                 @type string $year  The four-digit year. Default empty. Accepts any four-digit year.
     78         *                 @type string $month Optional when passing array.The month of the year.
     79         *                                     Default (string:empty)|(array:12). Accepts numbers 1-12.
     80         *                 @type string $day   Optional when passing array.The day of the month.
     81         *                                     Default (string:empty)|(array:last day of month). Accepts numbers 1-31.
     82         *             }
     83         *             @type string       $column    Optional. Used to add a clause comparing a column other than the column
     84         *                                           specified in the top-level $column paramater.  Default is the value
     85         *                                           of top-level $column. Accepts 'post_date', 'post_date_gmt',
     86         *                                           'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt'.
     87         *             @type string       $compare   Optional. The comparison operator. Default '='. Accepts '=', '!=',
     88         *                                           '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
     89         *             @type bool         $inclusive Optional. Include results from dates specified in 'before' or 'after'.
     90         *                                           Default. Accepts.
     91         *             @type int          $year      Optional. The four-digit near number. Default empty. Accepts any
     92         *                                           four-digit year.
     93         *             @type int          $month     Optional. The two-digit month number. Default empty. Accepts numbers 1-12.
     94         *             @type int          $week      Optional. The week number of the year. Default empty. Accepts numbers 0-53.
     95         *             @type int          $day       Optional. The day of the month. Default empty. Accepts numbers 1-31.
     96         *             @type int          $hour      Optional. The hour of the day. Default empty. Accepts numbers 0-23.
     97         *             @type int          $minute    Optional. The minute of the hour. Default empty. Accepts numbers 0-60.
     98         *             @type int          $second    Optional. The second of the minute. Default empty. Accepts numbers 0-60.
     99         *         }
     100         *     }
     101         * }
     102         * @param array $default_column Optional. Default column to query against. Default 'post_date'. Accepts 'post_date',
     103         *                              'post_date_gmt', 'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt'.
    81104         */
    82105        function __construct( $date_query, $default_column = 'post_date' ) {
    83106                if ( empty( $date_query ) || ! is_array( $date_query ) )
     
    136159         * @return string A validated column name value.
    137160         */
    138161        public function validate_column( $column ) {
     162                /**
     163                 * Filter the list of valid date query columns.
     164                 *
     165                 * @since 3.7.0
     166                 *
     167                 * @param array $columns An array of valid date query columns. Defaults are 'post_date', 'post_date_gmt',
     168                 *                       'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt'
     169                 */
    139170                if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', array( 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt' ) ) ) )
    140171                        $column = 'post_date';
    141172
     
    168199                else
    169200                        $where = '';
    170201
     202                /**
     203                 * Filter the date query WHERE string.
     204                 *
     205                 * @since 3.7.0
     206                 *
     207                 * @param string        $where WHERE clause of the date query.
     208                 * @param WP_Date_Query $this  The WP_Date_Query instance.
     209                 */
    171210                return apply_filters( 'get_date_sql', $where, $this );
    172211        }
    173212