wp/wp-includes/class-wp-date-query.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    51 
    51 
    52 	/**
    52 	/**
    53 	 * Supported time-related parameter keys.
    53 	 * Supported time-related parameter keys.
    54 	 *
    54 	 *
    55 	 * @since 4.1.0
    55 	 * @since 4.1.0
    56 	 * @var array
    56 	 * @var string[]
    57 	 */
    57 	 */
    58 	public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second' );
    58 	public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second' );
    59 
    59 
    60 	/**
    60 	/**
    61 	 * Constructor.
    61 	 * Constructor.
    72 	 * @param array  $date_query {
    72 	 * @param array  $date_query {
    73 	 *     Array of date query clauses.
    73 	 *     Array of date query clauses.
    74 	 *
    74 	 *
    75 	 *     @type array ...$0 {
    75 	 *     @type array ...$0 {
    76 	 *         @type string $column   Optional. The column to query against. If undefined, inherits the value of
    76 	 *         @type string $column   Optional. The column to query against. If undefined, inherits the value of
    77 	 *                                the `$default_column` parameter. Accepts 'post_date', 'post_date_gmt',
    77 	 *                                the `$default_column` parameter. See WP_Date_Query::validate_column() and
    78 	 *                                'post_modified','post_modified_gmt', 'comment_date', 'comment_date_gmt'.
    78 	 *                                the {@see 'date_query_valid_columns'} filter for the list of accepted values.
    79 	 *                                Default 'post_date'.
    79 	 *                                Default 'post_date'.
    80 	 *         @type string $compare  Optional. The comparison operator. Accepts '=', '!=', '>', '>=', '<', '<=',
    80 	 *         @type string $compare  Optional. The comparison operator. Accepts '=', '!=', '>', '>=', '<', '<=',
    81 	 *                                'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. Default '='.
    81 	 *                                'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. Default '='.
    82 	 *         @type string $relation Optional. The boolean relationship between the date queries. Accepts 'OR' or 'AND'.
    82 	 *         @type string $relation Optional. The boolean relationship between the date queries. Accepts 'OR' or 'AND'.
    83 	 *                                Default 'OR'.
    83 	 *                                Default 'OR'.
   102 	 *                 @type string $month Optional when passing array. The month of the year. Accepts numbers 1-12.
   102 	 *                 @type string $month Optional when passing array. The month of the year. Accepts numbers 1-12.
   103 	 *                                     Default (string:empty)|(array:12).
   103 	 *                                     Default (string:empty)|(array:12).
   104 	 *                 @type string $day   Optional when passing array.The day of the month. Accepts numbers 1-31.
   104 	 *                 @type string $day   Optional when passing array.The day of the month. Accepts numbers 1-31.
   105 	 *                                     Default (string:empty)|(array:last day of month).
   105 	 *                                     Default (string:empty)|(array:last day of month).
   106 	 *             }
   106 	 *             }
   107 	 *             @type string       $column        Optional. Used to add a clause comparing a column other than the
   107 	 *             @type string       $column        Optional. Used to add a clause comparing a column other than
   108 	 *                                               column specified in the top-level `$column` parameter. Accepts
   108 	 *                                               the column specified in the top-level `$column` parameter.
   109 	 *                                               'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt',
   109 	 *                                               See WP_Date_Query::validate_column() and
   110 	 *                                               'comment_date', 'comment_date_gmt'. Default is the value of
   110 	 *                                               the {@see 'date_query_valid_columns'} filter for the list
   111 	 *                                               top-level `$column`.
   111 	 *                                               of accepted values. Default is the value of top-level `$column`.
   112 	 *             @type string       $compare       Optional. The comparison operator. Accepts '=', '!=', '>', '>=',
   112 	 *             @type string       $compare       Optional. The comparison operator. Accepts '=', '!=', '>', '>=',
   113 	 *                                               '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. 'IN',
   113 	 *                                               '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. 'IN',
   114 	 *                                               'NOT IN', 'BETWEEN', and 'NOT BETWEEN'. Comparisons support
   114 	 *                                               'NOT IN', 'BETWEEN', and 'NOT BETWEEN'. Comparisons support
   115 	 *                                               arrays in some time-related parameters. Default '='.
   115 	 *                                               arrays in some time-related parameters. Default '='.
   116 	 *             @type bool         $inclusive     Optional. Include results from dates specified in 'before' or
   116 	 *             @type bool         $inclusive     Optional. Include results from dates specified in 'before' or
   131 	 *             @type int|int[]    $dayofweek_iso Optional. The day number of the week (ISO). Accepts numbers 1-7
   131 	 *             @type int|int[]    $dayofweek_iso Optional. The day number of the week (ISO). Accepts numbers 1-7
   132 	 *                                               (1 is Monday) or an array of valid numbers if `$compare` supports it.
   132 	 *                                               (1 is Monday) or an array of valid numbers if `$compare` supports it.
   133 	 *                                               Default empty.
   133 	 *                                               Default empty.
   134 	 *             @type int|int[]    $hour          Optional. The hour of the day. Accepts numbers 0-23 or an array
   134 	 *             @type int|int[]    $hour          Optional. The hour of the day. Accepts numbers 0-23 or an array
   135 	 *                                               of valid numbers if `$compare` supports it. Default empty.
   135 	 *                                               of valid numbers if `$compare` supports it. Default empty.
   136 	 *             @type int|int[]    $minute        Optional. The minute of the hour. Accepts numbers 0-60 or an array
   136 	 *             @type int|int[]    $minute        Optional. The minute of the hour. Accepts numbers 0-59 or an array
   137 	 *                                               of valid numbers if `$compare` supports it. Default empty.
   137 	 *                                               of valid numbers if `$compare` supports it. Default empty.
   138 	 *             @type int|int[]    $second        Optional. The second of the minute. Accepts numbers 0-60 or an
   138 	 *             @type int|int[]    $second        Optional. The second of the minute. Accepts numbers 0-59 or an
   139 	 *                                               array of valid numbers if `$compare` supports it. Default empty.
   139 	 *                                               array of valid numbers if `$compare` supports it. Default empty.
   140 	 *         }
   140 	 *         }
   141 	 *     }
   141 	 *     }
   142 	 * }
   142 	 * }
   143 	 * @param string $default_column Optional. Default column to query against. Default 'post_date'.
   143 	 * @param string $default_column Optional. Default column to query against. See WP_Date_Query::validate_column()
   144 	 *                               Accepts 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt',
   144 	 *                               and the {@see 'date_query_valid_columns'} filter for the list of accepted values.
   145 	 *                               'comment_date', 'comment_date_gmt'.
   145 	 *                               Default 'post_date'.
   146 	 */
   146 	 */
   147 	public function __construct( $date_query, $default_column = 'post_date' ) {
   147 	public function __construct( $date_query, $default_column = 'post_date' ) {
   148 		if ( empty( $date_query ) || ! is_array( $date_query ) ) {
   148 		if ( empty( $date_query ) || ! is_array( $date_query ) ) {
   149 			return;
   149 			return;
   150 		}
   150 		}
   492 			/**
   492 			/**
   493 			 * Filters the list of valid date query columns.
   493 			 * Filters the list of valid date query columns.
   494 			 *
   494 			 *
   495 			 * @since 3.7.0
   495 			 * @since 3.7.0
   496 			 * @since 4.1.0 Added 'user_registered' to the default recognized columns.
   496 			 * @since 4.1.0 Added 'user_registered' to the default recognized columns.
       
   497 			 * @since 4.6.0 Added 'registered' and 'last_updated' to the default recognized columns.
   497 			 *
   498 			 *
   498 			 * @param string[] $valid_columns An array of valid date query columns. Defaults
   499 			 * @param string[] $valid_columns An array of valid date query columns. Defaults
   499 			 *                                are 'post_date', 'post_date_gmt', 'post_modified',
   500 			 *                                are 'post_date', 'post_date_gmt', 'post_modified',
   500 			 *                                'post_modified_gmt', 'comment_date', 'comment_date_gmt',
   501 			 *                                'post_modified_gmt', 'comment_date', 'comment_date_gmt',
   501 			 *                                'user_registered'
   502 			 *                                'user_registered', 'registered', 'last_updated'.
   502 			 */
   503 			 */
   503 			if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ), true ) ) {
   504 			if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ), true ) ) {
   504 				$column = 'post_date';
   505 				$column = 'post_date';
   505 			}
   506 			}
   506 
   507 
   553 		 * Filters the date query WHERE clause.
   554 		 * Filters the date query WHERE clause.
   554 		 *
   555 		 *
   555 		 * @since 3.7.0
   556 		 * @since 3.7.0
   556 		 *
   557 		 *
   557 		 * @param string        $where WHERE clause of the date query.
   558 		 * @param string        $where WHERE clause of the date query.
   558 		 * @param WP_Date_Query $this  The WP_Date_Query instance.
   559 		 * @param WP_Date_Query $query The WP_Date_Query instance.
   559 		 */
   560 		 */
   560 		return apply_filters( 'get_date_sql', $where, $this );
   561 		return apply_filters( 'get_date_sql', $where, $this );
   561 	}
   562 	}
   562 
   563 
   563 	/**
   564 	/**
   566 	 * Called by the public WP_Date_Query::get_sql(), this method is abstracted
   567 	 * Called by the public WP_Date_Query::get_sql(), this method is abstracted
   567 	 * out to maintain parity with the other Query classes.
   568 	 * out to maintain parity with the other Query classes.
   568 	 *
   569 	 *
   569 	 * @since 4.1.0
   570 	 * @since 4.1.0
   570 	 *
   571 	 *
   571 	 * @return array {
   572 	 * @return string[] {
   572 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
   573 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
   573 	 *
   574 	 *
   574 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   575 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   575 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   576 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   576 	 * }
   577 	 * }
   676 	 * compatibility while retaining the naming convention across Query classes.
   677 	 * compatibility while retaining the naming convention across Query classes.
   677 	 *
   678 	 *
   678 	 * @since 3.7.0
   679 	 * @since 3.7.0
   679 	 *
   680 	 *
   680 	 * @param array $query Date query arguments.
   681 	 * @param array $query Date query arguments.
   681 	 * @return array {
   682 	 * @return string[] {
   682 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
   683 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
   683 	 *
   684 	 *
   684 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   685 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   685 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   686 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   686 	 * }
   687 	 * }
   694 	 *
   695 	 *
   695 	 * @since 4.1.0
   696 	 * @since 4.1.0
   696 	 *
   697 	 *
   697 	 * @param array $query        Date query clause.
   698 	 * @param array $query        Date query clause.
   698 	 * @param array $parent_query Parent query of the current date query.
   699 	 * @param array $parent_query Parent query of the current date query.
   699 	 * @return array {
   700 	 * @return string[] {
   700 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
   701 	 *     Array containing JOIN and WHERE SQL clauses to append to the main query.
   701 	 *
   702 	 *
   702 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   703 	 *     @type string $join  SQL fragment to append to the main JOIN clause.
   703 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   704 	 *     @type string $where SQL fragment to append to the main WHERE clause.
   704 	 * }
   705 	 * }