Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: class-wp-date-query.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Class for generating SQL clauses that filter a primary query according to date.
[2] Fix | Delete
*
[3] Fix | Delete
* WP_Date_Query is a helper that allows primary query classes, such as WP_Query, to filter
[4] Fix | Delete
* their results by date columns, by generating `WHERE` subclauses to be attached to the
[5] Fix | Delete
* primary SQL query string.
[6] Fix | Delete
*
[7] Fix | Delete
* Attempting to filter by an invalid date value (eg month=13) will generate SQL that will
[8] Fix | Delete
* return no results. In these cases, a _doing_it_wrong() error notice is also thrown.
[9] Fix | Delete
* See WP_Date_Query::validate_date_values().
[10] Fix | Delete
*
[11] Fix | Delete
* @link https://developer.wordpress.org/reference/classes/wp_query/
[12] Fix | Delete
*
[13] Fix | Delete
* @since 3.7.0
[14] Fix | Delete
*/
[15] Fix | Delete
#[AllowDynamicProperties]
[16] Fix | Delete
class WP_Date_Query {
[17] Fix | Delete
/**
[18] Fix | Delete
* Array of date queries.
[19] Fix | Delete
*
[20] Fix | Delete
* See WP_Date_Query::__construct() for information on date query arguments.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 3.7.0
[23] Fix | Delete
* @var array
[24] Fix | Delete
*/
[25] Fix | Delete
public $queries = array();
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* The default relation between top-level queries. Can be either 'AND' or 'OR'.
[29] Fix | Delete
*
[30] Fix | Delete
* @since 3.7.0
[31] Fix | Delete
* @var string
[32] Fix | Delete
*/
[33] Fix | Delete
public $relation = 'AND';
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* The column to query against. Can be changed via the query arguments.
[37] Fix | Delete
*
[38] Fix | Delete
* @since 3.7.0
[39] Fix | Delete
* @var string
[40] Fix | Delete
*/
[41] Fix | Delete
public $column = 'post_date';
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* The value comparison operator. Can be changed via the query arguments.
[45] Fix | Delete
*
[46] Fix | Delete
* @since 3.7.0
[47] Fix | Delete
* @var string
[48] Fix | Delete
*/
[49] Fix | Delete
public $compare = '=';
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Supported time-related parameter keys.
[53] Fix | Delete
*
[54] Fix | Delete
* @since 4.1.0
[55] Fix | Delete
* @var string[]
[56] Fix | Delete
*/
[57] Fix | Delete
public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second' );
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Constructor.
[61] Fix | Delete
*
[62] Fix | Delete
* Time-related parameters that normally require integer values ('year', 'month', 'week', 'dayofyear', 'day',
[63] Fix | Delete
* 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second') accept arrays of integers for some values of
[64] Fix | Delete
* 'compare'. When 'compare' is 'IN' or 'NOT IN', arrays are accepted; when 'compare' is 'BETWEEN' or 'NOT
[65] Fix | Delete
* BETWEEN', arrays of two valid values are required. See individual argument descriptions for accepted values.
[66] Fix | Delete
*
[67] Fix | Delete
* @since 3.7.0
[68] Fix | Delete
* @since 4.0.0 The $inclusive logic was updated to include all times within the date range.
[69] Fix | Delete
* @since 4.1.0 Introduced 'dayofweek_iso' time type parameter.
[70] Fix | Delete
*
[71] Fix | Delete
* @param array $date_query {
[72] Fix | Delete
* Array of date query clauses.
[73] Fix | Delete
*
[74] Fix | Delete
* @type array ...$0 {
[75] Fix | Delete
* @type string $column Optional. The column to query against. If undefined, inherits the value of
[76] Fix | Delete
* the `$default_column` parameter. See WP_Date_Query::validate_column() and
[77] Fix | Delete
* the {@see 'date_query_valid_columns'} filter for the list of accepted values.
[78] Fix | Delete
* Default 'post_date'.
[79] Fix | Delete
* @type string $compare Optional. The comparison operator. Accepts '=', '!=', '>', '>=', '<', '<=',
[80] Fix | Delete
* 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. Default '='.
[81] Fix | Delete
* @type string $relation Optional. The boolean relationship between the date queries. Accepts 'OR' or 'AND'.
[82] Fix | Delete
* Default 'OR'.
[83] Fix | Delete
* @type array ...$0 {
[84] Fix | Delete
* Optional. An array of first-order clause parameters, or another fully-formed date query.
[85] Fix | Delete
*
[86] Fix | Delete
* @type string|array $before {
[87] Fix | Delete
* Optional. Date to retrieve posts before. Accepts `strtotime()`-compatible string,
[88] Fix | Delete
* or array of 'year', 'month', 'day' values.
[89] Fix | Delete
*
[90] Fix | Delete
* @type string $year The four-digit year. Default empty. Accepts any four-digit year.
[91] Fix | Delete
* @type string $month Optional when passing array.The month of the year.
[92] Fix | Delete
* Default (string:empty)|(array:1). Accepts numbers 1-12.
[93] Fix | Delete
* @type string $day Optional when passing array.The day of the month.
[94] Fix | Delete
* Default (string:empty)|(array:1). Accepts numbers 1-31.
[95] Fix | Delete
* }
[96] Fix | Delete
* @type string|array $after {
[97] Fix | Delete
* Optional. Date to retrieve posts after. Accepts `strtotime()`-compatible string,
[98] Fix | Delete
* or array of 'year', 'month', 'day' values.
[99] Fix | Delete
*
[100] Fix | Delete
* @type string $year The four-digit year. Accepts any four-digit year. Default empty.
[101] Fix | Delete
* @type string $month Optional when passing array. The month of the year. Accepts numbers 1-12.
[102] Fix | Delete
* Default (string:empty)|(array:12).
[103] Fix | Delete
* @type string $day Optional when passing array.The day of the month. Accepts numbers 1-31.
[104] Fix | Delete
* Default (string:empty)|(array:last day of month).
[105] Fix | Delete
* }
[106] Fix | Delete
* @type string $column Optional. Used to add a clause comparing a column other than
[107] Fix | Delete
* the column specified in the top-level `$column` parameter.
[108] Fix | Delete
* See WP_Date_Query::validate_column() and
[109] Fix | Delete
* the {@see 'date_query_valid_columns'} filter for the list
[110] Fix | Delete
* of accepted values. Default is the value of top-level `$column`.
[111] Fix | Delete
* @type string $compare Optional. The comparison operator. Accepts '=', '!=', '>', '>=',
[112] Fix | Delete
* '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. 'IN',
[113] Fix | Delete
* 'NOT IN', 'BETWEEN', and 'NOT BETWEEN'. Comparisons support
[114] Fix | Delete
* arrays in some time-related parameters. Default '='.
[115] Fix | Delete
* @type bool $inclusive Optional. Include results from dates specified in 'before' or
[116] Fix | Delete
* 'after'. Default false.
[117] Fix | Delete
* @type int|int[] $year Optional. The four-digit year number. Accepts any four-digit year
[118] Fix | Delete
* or an array of years if `$compare` supports it. Default empty.
[119] Fix | Delete
* @type int|int[] $month Optional. The two-digit month number. Accepts numbers 1-12 or an
[120] Fix | Delete
* array of valid numbers if `$compare` supports it. Default empty.
[121] Fix | Delete
* @type int|int[] $week Optional. The week number of the year. Accepts numbers 0-53 or an
[122] Fix | Delete
* array of valid numbers if `$compare` supports it. Default empty.
[123] Fix | Delete
* @type int|int[] $dayofyear Optional. The day number of the year. Accepts numbers 1-366 or an
[124] Fix | Delete
* array of valid numbers if `$compare` supports it.
[125] Fix | Delete
* @type int|int[] $day Optional. The day of the month. Accepts numbers 1-31 or an array
[126] Fix | Delete
* of valid numbers if `$compare` supports it. Default empty.
[127] Fix | Delete
* @type int|int[] $dayofweek Optional. The day number of the week. Accepts numbers 1-7 (1 is
[128] Fix | Delete
* Sunday) or an array of valid numbers if `$compare` supports it.
[129] Fix | Delete
* Default empty.
[130] Fix | Delete
* @type int|int[] $dayofweek_iso Optional. The day number of the week (ISO). Accepts numbers 1-7
[131] Fix | Delete
* (1 is Monday) or an array of valid numbers if `$compare` supports it.
[132] Fix | Delete
* Default empty.
[133] Fix | Delete
* @type int|int[] $hour Optional. The hour of the day. Accepts numbers 0-23 or an array
[134] Fix | Delete
* of valid numbers if `$compare` supports it. Default empty.
[135] Fix | Delete
* @type int|int[] $minute Optional. The minute of the hour. Accepts numbers 0-59 or an array
[136] Fix | Delete
* of valid numbers if `$compare` supports it. Default empty.
[137] Fix | Delete
* @type int|int[] $second Optional. The second of the minute. Accepts numbers 0-59 or an
[138] Fix | Delete
* array of valid numbers if `$compare` supports it. Default empty.
[139] Fix | Delete
* }
[140] Fix | Delete
* }
[141] Fix | Delete
* }
[142] Fix | Delete
* @param string $default_column Optional. Default column to query against. See WP_Date_Query::validate_column()
[143] Fix | Delete
* and the {@see 'date_query_valid_columns'} filter for the list of accepted values.
[144] Fix | Delete
* Default 'post_date'.
[145] Fix | Delete
*/
[146] Fix | Delete
public function __construct( $date_query, $default_column = 'post_date' ) {
[147] Fix | Delete
if ( empty( $date_query ) || ! is_array( $date_query ) ) {
[148] Fix | Delete
return;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
if ( isset( $date_query['relation'] ) ) {
[152] Fix | Delete
$this->relation = $this->sanitize_relation( $date_query['relation'] );
[153] Fix | Delete
} else {
[154] Fix | Delete
$this->relation = 'AND';
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
// Support for passing time-based keys in the top level of the $date_query array.
[158] Fix | Delete
if ( ! isset( $date_query[0] ) ) {
[159] Fix | Delete
$date_query = array( $date_query );
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
if ( ! empty( $date_query['column'] ) ) {
[163] Fix | Delete
$date_query['column'] = esc_sql( $date_query['column'] );
[164] Fix | Delete
} else {
[165] Fix | Delete
$date_query['column'] = esc_sql( $default_column );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
$this->column = $this->validate_column( $this->column );
[169] Fix | Delete
[170] Fix | Delete
$this->compare = $this->get_compare( $date_query );
[171] Fix | Delete
[172] Fix | Delete
$this->queries = $this->sanitize_query( $date_query );
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Recursive-friendly query sanitizer.
[177] Fix | Delete
*
[178] Fix | Delete
* Ensures that each query-level clause has a 'relation' key, and that
[179] Fix | Delete
* each first-order clause contains all the necessary keys from `$defaults`.
[180] Fix | Delete
*
[181] Fix | Delete
* @since 4.1.0
[182] Fix | Delete
*
[183] Fix | Delete
* @param array $queries
[184] Fix | Delete
* @param array $parent_query
[185] Fix | Delete
* @return array Sanitized queries.
[186] Fix | Delete
*/
[187] Fix | Delete
public function sanitize_query( $queries, $parent_query = null ) {
[188] Fix | Delete
$cleaned_query = array();
[189] Fix | Delete
[190] Fix | Delete
$defaults = array(
[191] Fix | Delete
'column' => 'post_date',
[192] Fix | Delete
'compare' => '=',
[193] Fix | Delete
'relation' => 'AND',
[194] Fix | Delete
);
[195] Fix | Delete
[196] Fix | Delete
// Numeric keys should always have array values.
[197] Fix | Delete
foreach ( $queries as $qkey => $qvalue ) {
[198] Fix | Delete
if ( is_numeric( $qkey ) && ! is_array( $qvalue ) ) {
[199] Fix | Delete
unset( $queries[ $qkey ] );
[200] Fix | Delete
}
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
// Each query should have a value for each default key. Inherit from the parent when possible.
[204] Fix | Delete
foreach ( $defaults as $dkey => $dvalue ) {
[205] Fix | Delete
if ( isset( $queries[ $dkey ] ) ) {
[206] Fix | Delete
continue;
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
if ( isset( $parent_query[ $dkey ] ) ) {
[210] Fix | Delete
$queries[ $dkey ] = $parent_query[ $dkey ];
[211] Fix | Delete
} else {
[212] Fix | Delete
$queries[ $dkey ] = $dvalue;
[213] Fix | Delete
}
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
// Validate the dates passed in the query.
[217] Fix | Delete
if ( $this->is_first_order_clause( $queries ) ) {
[218] Fix | Delete
$this->validate_date_values( $queries );
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
// Sanitize the relation parameter.
[222] Fix | Delete
$queries['relation'] = $this->sanitize_relation( $queries['relation'] );
[223] Fix | Delete
[224] Fix | Delete
foreach ( $queries as $key => $q ) {
[225] Fix | Delete
if ( ! is_array( $q ) || in_array( $key, $this->time_keys, true ) ) {
[226] Fix | Delete
// This is a first-order query. Trust the values and sanitize when building SQL.
[227] Fix | Delete
$cleaned_query[ $key ] = $q;
[228] Fix | Delete
} else {
[229] Fix | Delete
// Any array without a time key is another query, so we recurse.
[230] Fix | Delete
$cleaned_query[] = $this->sanitize_query( $q, $queries );
[231] Fix | Delete
}
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
return $cleaned_query;
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Determines whether this is a first-order clause.
[239] Fix | Delete
*
[240] Fix | Delete
* Checks to see if the current clause has any time-related keys.
[241] Fix | Delete
* If so, it's first-order.
[242] Fix | Delete
*
[243] Fix | Delete
* @since 4.1.0
[244] Fix | Delete
*
[245] Fix | Delete
* @param array $query Query clause.
[246] Fix | Delete
* @return bool True if this is a first-order clause.
[247] Fix | Delete
*/
[248] Fix | Delete
protected function is_first_order_clause( $query ) {
[249] Fix | Delete
$time_keys = array_intersect( $this->time_keys, array_keys( $query ) );
[250] Fix | Delete
return ! empty( $time_keys );
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Determines and validates what comparison operator to use.
[255] Fix | Delete
*
[256] Fix | Delete
* @since 3.7.0
[257] Fix | Delete
*
[258] Fix | Delete
* @param array $query A date query or a date subquery.
[259] Fix | Delete
* @return string The comparison operator.
[260] Fix | Delete
*/
[261] Fix | Delete
public function get_compare( $query ) {
[262] Fix | Delete
if ( ! empty( $query['compare'] )
[263] Fix | Delete
&& in_array( $query['compare'], array( '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ), true )
[264] Fix | Delete
) {
[265] Fix | Delete
return strtoupper( $query['compare'] );
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
return $this->compare;
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
/**
[272] Fix | Delete
* Validates the given date_query values and triggers errors if something is not valid.
[273] Fix | Delete
*
[274] Fix | Delete
* Note that date queries with invalid date ranges are allowed to
[275] Fix | Delete
* continue (though of course no items will be found for impossible dates).
[276] Fix | Delete
* This method only generates debug notices for these cases.
[277] Fix | Delete
*
[278] Fix | Delete
* @since 4.1.0
[279] Fix | Delete
*
[280] Fix | Delete
* @param array $date_query The date_query array.
[281] Fix | Delete
* @return bool True if all values in the query are valid, false if one or more fail.
[282] Fix | Delete
*/
[283] Fix | Delete
public function validate_date_values( $date_query = array() ) {
[284] Fix | Delete
if ( empty( $date_query ) ) {
[285] Fix | Delete
return false;
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
$valid = true;
[289] Fix | Delete
[290] Fix | Delete
/*
[291] Fix | Delete
* Validate 'before' and 'after' up front, then let the
[292] Fix | Delete
* validation routine continue to be sure that all invalid
[293] Fix | Delete
* values generate errors too.
[294] Fix | Delete
*/
[295] Fix | Delete
if ( array_key_exists( 'before', $date_query ) && is_array( $date_query['before'] ) ) {
[296] Fix | Delete
$valid = $this->validate_date_values( $date_query['before'] );
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
if ( array_key_exists( 'after', $date_query ) && is_array( $date_query['after'] ) ) {
[300] Fix | Delete
$valid = $this->validate_date_values( $date_query['after'] );
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
// Array containing all min-max checks.
[304] Fix | Delete
$min_max_checks = array();
[305] Fix | Delete
[306] Fix | Delete
// Days per year.
[307] Fix | Delete
if ( array_key_exists( 'year', $date_query ) ) {
[308] Fix | Delete
/*
[309] Fix | Delete
* If a year exists in the date query, we can use it to get the days.
[310] Fix | Delete
* If multiple years are provided (as in a BETWEEN), use the first one.
[311] Fix | Delete
*/
[312] Fix | Delete
if ( is_array( $date_query['year'] ) ) {
[313] Fix | Delete
$_year = reset( $date_query['year'] );
[314] Fix | Delete
} else {
[315] Fix | Delete
$_year = $date_query['year'];
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
$max_days_of_year = gmdate( 'z', mktime( 0, 0, 0, 12, 31, $_year ) ) + 1;
[319] Fix | Delete
} else {
[320] Fix | Delete
// Otherwise we use the max of 366 (leap-year).
[321] Fix | Delete
$max_days_of_year = 366;
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
$min_max_checks['dayofyear'] = array(
[325] Fix | Delete
'min' => 1,
[326] Fix | Delete
'max' => $max_days_of_year,
[327] Fix | Delete
);
[328] Fix | Delete
[329] Fix | Delete
// Days per week.
[330] Fix | Delete
$min_max_checks['dayofweek'] = array(
[331] Fix | Delete
'min' => 1,
[332] Fix | Delete
'max' => 7,
[333] Fix | Delete
);
[334] Fix | Delete
[335] Fix | Delete
// Days per week.
[336] Fix | Delete
$min_max_checks['dayofweek_iso'] = array(
[337] Fix | Delete
'min' => 1,
[338] Fix | Delete
'max' => 7,
[339] Fix | Delete
);
[340] Fix | Delete
[341] Fix | Delete
// Months per year.
[342] Fix | Delete
$min_max_checks['month'] = array(
[343] Fix | Delete
'min' => 1,
[344] Fix | Delete
'max' => 12,
[345] Fix | Delete
);
[346] Fix | Delete
[347] Fix | Delete
// Weeks per year.
[348] Fix | Delete
if ( isset( $_year ) ) {
[349] Fix | Delete
/*
[350] Fix | Delete
* If we have a specific year, use it to calculate number of weeks.
[351] Fix | Delete
* Note: the number of weeks in a year is the date in which Dec 28 appears.
[352] Fix | Delete
*/
[353] Fix | Delete
$week_count = gmdate( 'W', mktime( 0, 0, 0, 12, 28, $_year ) );
[354] Fix | Delete
[355] Fix | Delete
} else {
[356] Fix | Delete
// Otherwise set the week-count to a maximum of 53.
[357] Fix | Delete
$week_count = 53;
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
$min_max_checks['week'] = array(
[361] Fix | Delete
'min' => 1,
[362] Fix | Delete
'max' => $week_count,
[363] Fix | Delete
);
[364] Fix | Delete
[365] Fix | Delete
// Days per month.
[366] Fix | Delete
$min_max_checks['day'] = array(
[367] Fix | Delete
'min' => 1,
[368] Fix | Delete
'max' => 31,
[369] Fix | Delete
);
[370] Fix | Delete
[371] Fix | Delete
// Hours per day.
[372] Fix | Delete
$min_max_checks['hour'] = array(
[373] Fix | Delete
'min' => 0,
[374] Fix | Delete
'max' => 23,
[375] Fix | Delete
);
[376] Fix | Delete
[377] Fix | Delete
// Minutes per hour.
[378] Fix | Delete
$min_max_checks['minute'] = array(
[379] Fix | Delete
'min' => 0,
[380] Fix | Delete
'max' => 59,
[381] Fix | Delete
);
[382] Fix | Delete
[383] Fix | Delete
// Seconds per minute.
[384] Fix | Delete
$min_max_checks['second'] = array(
[385] Fix | Delete
'min' => 0,
[386] Fix | Delete
'max' => 59,
[387] Fix | Delete
);
[388] Fix | Delete
[389] Fix | Delete
// Concatenate and throw a notice for each invalid value.
[390] Fix | Delete
foreach ( $min_max_checks as $key => $check ) {
[391] Fix | Delete
if ( ! array_key_exists( $key, $date_query ) ) {
[392] Fix | Delete
continue;
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
// Throw a notice for each failing value.
[396] Fix | Delete
foreach ( (array) $date_query[ $key ] as $_value ) {
[397] Fix | Delete
$is_between = $_value >= $check['min'] && $_value <= $check['max'];
[398] Fix | Delete
[399] Fix | Delete
if ( ! is_numeric( $_value ) || ! $is_between ) {
[400] Fix | Delete
$error = sprintf(
[401] Fix | Delete
/* translators: Date query invalid date message. 1: Invalid value, 2: Type of value, 3: Minimum valid value, 4: Maximum valid value. */
[402] Fix | Delete
__( 'Invalid value %1$s for %2$s. Expected value should be between %3$s and %4$s.' ),
[403] Fix | Delete
'<code>' . esc_html( $_value ) . '</code>',
[404] Fix | Delete
'<code>' . esc_html( $key ) . '</code>',
[405] Fix | Delete
'<code>' . esc_html( $check['min'] ) . '</code>',
[406] Fix | Delete
'<code>' . esc_html( $check['max'] ) . '</code>'
[407] Fix | Delete
);
[408] Fix | Delete
[409] Fix | Delete
_doing_it_wrong( __CLASS__, $error, '4.1.0' );
[410] Fix | Delete
[411] Fix | Delete
$valid = false;
[412] Fix | Delete
}
[413] Fix | Delete
}
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
// If we already have invalid date messages, don't bother running through checkdate().
[417] Fix | Delete
if ( ! $valid ) {
[418] Fix | Delete
return $valid;
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
$day_month_year_error_msg = '';
[422] Fix | Delete
[423] Fix | Delete
$day_exists = array_key_exists( 'day', $date_query ) && is_numeric( $date_query['day'] );
[424] Fix | Delete
$month_exists = array_key_exists( 'month', $date_query ) && is_numeric( $date_query['month'] );
[425] Fix | Delete
$year_exists = array_key_exists( 'year', $date_query ) && is_numeric( $date_query['year'] );
[426] Fix | Delete
[427] Fix | Delete
if ( $day_exists && $month_exists && $year_exists ) {
[428] Fix | Delete
// 1. Checking day, month, year combination.
[429] Fix | Delete
if ( ! wp_checkdate( $date_query['month'], $date_query['day'], $date_query['year'], sprintf( '%s-%s-%s', $date_query['year'], $date_query['month'], $date_query['day'] ) ) ) {
[430] Fix | Delete
$day_month_year_error_msg = sprintf(
[431] Fix | Delete
/* translators: 1: Year, 2: Month, 3: Day of month. */
[432] Fix | Delete
__( 'The following values do not describe a valid date: year %1$s, month %2$s, day %3$s.' ),
[433] Fix | Delete
'<code>' . esc_html( $date_query['year'] ) . '</code>',
[434] Fix | Delete
'<code>' . esc_html( $date_query['month'] ) . '</code>',
[435] Fix | Delete
'<code>' . esc_html( $date_query['day'] ) . '</code>'
[436] Fix | Delete
);
[437] Fix | Delete
[438] Fix | Delete
$valid = false;
[439] Fix | Delete
}
[440] Fix | Delete
} elseif ( $day_exists && $month_exists ) {
[441] Fix | Delete
/*
[442] Fix | Delete
* 2. checking day, month combination
[443] Fix | Delete
* We use 2012 because, as a leap year, it's the most permissive.
[444] Fix | Delete
*/
[445] Fix | Delete
if ( ! wp_checkdate( $date_query['month'], $date_query['day'], 2012, sprintf( '2012-%s-%s', $date_query['month'], $date_query['day'] ) ) ) {
[446] Fix | Delete
$day_month_year_error_msg = sprintf(
[447] Fix | Delete
/* translators: 1: Month, 2: Day of month. */
[448] Fix | Delete
__( 'The following values do not describe a valid date: month %1$s, day %2$s.' ),
[449] Fix | Delete
'<code>' . esc_html( $date_query['month'] ) . '</code>',
[450] Fix | Delete
'<code>' . esc_html( $date_query['day'] ) . '</code>'
[451] Fix | Delete
);
[452] Fix | Delete
[453] Fix | Delete
$valid = false;
[454] Fix | Delete
}
[455] Fix | Delete
}
[456] Fix | Delete
[457] Fix | Delete
if ( ! empty( $day_month_year_error_msg ) ) {
[458] Fix | Delete
_doing_it_wrong( __CLASS__, $day_month_year_error_msg, '4.1.0' );
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
return $valid;
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
/**
[465] Fix | Delete
* Validates a column name parameter.
[466] Fix | Delete
*
[467] Fix | Delete
* Column names without a table prefix (like 'post_date') are checked against a list of
[468] Fix | Delete
* allowed and known tables, and then, if found, have a table prefix (such as 'wp_posts.')
[469] Fix | Delete
* prepended. Prefixed column names (such as 'wp_posts.post_date') bypass this allowed
[470] Fix | Delete
* check, and are only sanitized to remove illegal characters.
[471] Fix | Delete
*
[472] Fix | Delete
* @since 3.7.0
[473] Fix | Delete
*
[474] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[475] Fix | Delete
*
[476] Fix | Delete
* @param string $column The user-supplied column name.
[477] Fix | Delete
* @return string A validated column name value.
[478] Fix | Delete
*/
[479] Fix | Delete
public function validate_column( $column ) {
[480] Fix | Delete
global $wpdb;
[481] Fix | Delete
[482] Fix | Delete
$valid_columns = array(
[483] Fix | Delete
'post_date',
[484] Fix | Delete
'post_date_gmt',
[485] Fix | Delete
'post_modified',
[486] Fix | Delete
'post_modified_gmt',
[487] Fix | Delete
'comment_date',
[488] Fix | Delete
'comment_date_gmt',
[489] Fix | Delete
'user_registered',
[490] Fix | Delete
'registered',
[491] Fix | Delete
'last_updated',
[492] Fix | Delete
);
[493] Fix | Delete
[494] Fix | Delete
// Attempt to detect a table prefix.
[495] Fix | Delete
if ( ! str_contains( $column, '.' ) ) {
[496] Fix | Delete
/**
[497] Fix | Delete
* Filters the list of valid date query columns.
[498] Fix | Delete
*
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function