Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/wpforms-.../src/Admin/Helpers
File: Datepicker.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Admin\Helpers;
[2] Fix | Delete
[3] Fix | Delete
use DateTimeImmutable;
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Timespan and popover date-picker helper methods.
[7] Fix | Delete
*
[8] Fix | Delete
* @since 1.8.2
[9] Fix | Delete
*/
[10] Fix | Delete
class Datepicker {
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Number of timespan days by default.
[14] Fix | Delete
* "Last 30 Days", by default.
[15] Fix | Delete
*
[16] Fix | Delete
* @since 1.8.2
[17] Fix | Delete
*/
[18] Fix | Delete
const TIMESPAN_DAYS = '30';
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Timespan (date range) delimiter.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 1.8.2
[24] Fix | Delete
*/
[25] Fix | Delete
const TIMESPAN_DELIMITER = ' - ';
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Default date format.
[29] Fix | Delete
*
[30] Fix | Delete
* @since 1.8.2
[31] Fix | Delete
*/
[32] Fix | Delete
const DATE_FORMAT = 'Y-m-d';
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Default date-time format.
[36] Fix | Delete
*
[37] Fix | Delete
* @since 1.8.2
[38] Fix | Delete
*/
[39] Fix | Delete
const DATETIME_FORMAT = 'Y-m-d H:i:s';
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Sets the timespan (or date range) selected.
[43] Fix | Delete
*
[44] Fix | Delete
* Includes:
[45] Fix | Delete
* 1. Start date object in WP timezone.
[46] Fix | Delete
* 2. End date object in WP timezone.
[47] Fix | Delete
* 3. Number of "Last X days", if applicable, otherwise returns "custom".
[48] Fix | Delete
* 4. Label associated with the selected date filter choice. @see "get_date_filter_choices".
[49] Fix | Delete
*
[50] Fix | Delete
* @since 1.8.2
[51] Fix | Delete
*
[52] Fix | Delete
* @return array
[53] Fix | Delete
*/
[54] Fix | Delete
public static function process_timespan() {
[55] Fix | Delete
[56] Fix | Delete
$dates = (string) filter_input( INPUT_GET, 'date', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
[57] Fix | Delete
[58] Fix | Delete
// Return default timespan if dates are empty.
[59] Fix | Delete
if ( empty( $dates ) ) {
[60] Fix | Delete
return self::get_timespan_dates( self::TIMESPAN_DAYS );
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
$dates = self::maybe_validate_string_timespan( $dates );
[64] Fix | Delete
[65] Fix | Delete
list( $start_date, $end_date ) = explode( self::TIMESPAN_DELIMITER, $dates );
[66] Fix | Delete
[67] Fix | Delete
// Return default timespan if start date is more recent than end date.
[68] Fix | Delete
if ( strtotime( $start_date ) > strtotime( $end_date ) ) {
[69] Fix | Delete
return self::get_timespan_dates( self::TIMESPAN_DAYS );
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
$timezone = wp_timezone(); // Retrieve the timezone string for the site.
[73] Fix | Delete
$start_date = date_create_immutable( $start_date, $timezone );
[74] Fix | Delete
$end_date = date_create_immutable( $end_date, $timezone );
[75] Fix | Delete
[76] Fix | Delete
// Return default timespan if date creation fails.
[77] Fix | Delete
if ( ! $start_date || ! $end_date ) {
[78] Fix | Delete
return self::get_timespan_dates( self::TIMESPAN_DAYS );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
// Set time to 0:0:0 for start date and 23:59:59 for end date.
[82] Fix | Delete
$start_date = $start_date->setTime( 0, 0, 0 );
[83] Fix | Delete
$end_date = $end_date->setTime( 23, 59, 59 );
[84] Fix | Delete
[85] Fix | Delete
$days_diff = '';
[86] Fix | Delete
$current_date = date_create_immutable( 'now', $timezone )->setTime( 23, 59, 59 );
[87] Fix | Delete
[88] Fix | Delete
// Calculate days difference only if end date is equal to current date.
[89] Fix | Delete
if ( ! $current_date->diff( $end_date )->format( '%a' ) ) {
[90] Fix | Delete
$days_diff = $end_date->diff( $start_date )->format( '%a' );
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
list( $days, $timespan_label ) = self::get_date_filter_choices( $days_diff );
[94] Fix | Delete
[95] Fix | Delete
return [
[96] Fix | Delete
$start_date, // WP timezone.
[97] Fix | Delete
$end_date, // WP timezone.
[98] Fix | Delete
$days, // e.g., 22.
[99] Fix | Delete
$timespan_label, // e.g., Custom.
[100] Fix | Delete
];
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Sets the timespan (or date range) for performing mysql queries.
[105] Fix | Delete
*
[106] Fix | Delete
* Includes:
[107] Fix | Delete
* 1. Start date object in WP timezone.
[108] Fix | Delete
* 2. End date object in WP timezone.
[109] Fix | Delete
*
[110] Fix | Delete
* @param null|array $timespan Given timespan (dates) preferably in WP timezone.
[111] Fix | Delete
*
[112] Fix | Delete
* @since 1.8.2
[113] Fix | Delete
*
[114] Fix | Delete
* @return array
[115] Fix | Delete
*/
[116] Fix | Delete
public static function process_timespan_mysql( $timespan = null ) {
[117] Fix | Delete
[118] Fix | Delete
// Retrieve and validate timespan if none is given.
[119] Fix | Delete
if ( empty( $timespan ) || ! is_array( $timespan ) ) {
[120] Fix | Delete
$timespan = self::process_timespan();
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
list( $start_date, $end_date ) = $timespan; // Ideally should be in WP timezone.
[124] Fix | Delete
[125] Fix | Delete
// If the time period is not a date object, return empty values.
[126] Fix | Delete
if ( ! ( $start_date instanceof DateTimeImmutable ) || ! ( $end_date instanceof DateTimeImmutable ) ) {
[127] Fix | Delete
return [ '', '' ];
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
// If given timespan is already in UTC timezone, return as it is.
[131] Fix | Delete
if ( date_timezone_get( $start_date )->getName() === 'UTC' && date_timezone_get( $end_date )->getName() === 'UTC' ) {
[132] Fix | Delete
return [
[133] Fix | Delete
$start_date, // UTC timezone.
[134] Fix | Delete
$end_date, // UTC timezone.
[135] Fix | Delete
];
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$mysql_timezone = timezone_open( 'UTC' );
[139] Fix | Delete
[140] Fix | Delete
return [
[141] Fix | Delete
$start_date->setTimezone( $mysql_timezone ), // UTC timezone.
[142] Fix | Delete
$end_date->setTimezone( $mysql_timezone ), // UTC timezone.
[143] Fix | Delete
];
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Helper method to generate WP and UTC based date-time instances.
[148] Fix | Delete
*
[149] Fix | Delete
* Includes:
[150] Fix | Delete
* 1. Start date object in WP timezone.
[151] Fix | Delete
* 2. End date object in WP timezone.
[152] Fix | Delete
* 3. Start date object in UTC timezone.
[153] Fix | Delete
* 4. End date object in UTC timezone.
[154] Fix | Delete
*
[155] Fix | Delete
* @since 1.8.2
[156] Fix | Delete
*
[157] Fix | Delete
* @param string $dates Given timespan (dates) in string. i.e. "2023-01-16 - 2023-02-15".
[158] Fix | Delete
*
[159] Fix | Delete
* @return bool|array
[160] Fix | Delete
*/
[161] Fix | Delete
public static function process_string_timespan( $dates ) {
[162] Fix | Delete
[163] Fix | Delete
$dates = self::maybe_validate_string_timespan( $dates );
[164] Fix | Delete
[165] Fix | Delete
list( $start_date, $end_date ) = explode( self::TIMESPAN_DELIMITER, $dates );
[166] Fix | Delete
[167] Fix | Delete
// Return false if the start date is more recent than the end date.
[168] Fix | Delete
if ( strtotime( $start_date ) > strtotime( $end_date ) ) {
[169] Fix | Delete
return false;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
$timezone = wp_timezone(); // Retrieve the timezone object for the site.
[173] Fix | Delete
$start_date = date_create_immutable( $start_date, $timezone );
[174] Fix | Delete
$end_date = date_create_immutable( $end_date, $timezone );
[175] Fix | Delete
[176] Fix | Delete
// Return false if the date creation fails.
[177] Fix | Delete
if ( ! $start_date || ! $end_date ) {
[178] Fix | Delete
return false;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
// Set the time to 0:0:0 for the start date and 23:59:59 for the end date.
[182] Fix | Delete
$start_date = $start_date->setTime( 0, 0, 0 );
[183] Fix | Delete
$end_date = $end_date->setTime( 23, 59, 59 );
[184] Fix | Delete
[185] Fix | Delete
// Since we will need the initial datetime instances after the query,
[186] Fix | Delete
// we need to return new objects when modifications made.
[187] Fix | Delete
// Convert the dates to UTC timezone.
[188] Fix | Delete
$mysql_timezone = timezone_open( 'UTC' );
[189] Fix | Delete
$utc_start_date = $start_date->setTimezone( $mysql_timezone );
[190] Fix | Delete
$utc_end_date = $end_date->setTimezone( $mysql_timezone );
[191] Fix | Delete
[192] Fix | Delete
return [
[193] Fix | Delete
$start_date, // WP timezone.
[194] Fix | Delete
$end_date, // WP timezone.
[195] Fix | Delete
$utc_start_date, // UTC timezone.
[196] Fix | Delete
$utc_end_date, // UTC timezone.
[197] Fix | Delete
];
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Sets the timespan (or date range) for performing mysql queries.
[202] Fix | Delete
*
[203] Fix | Delete
* Includes:
[204] Fix | Delete
* 1. A list of date filter options for the datepicker module.
[205] Fix | Delete
* 2. Currently selected filter or date range values. Last "X" days, or i.e. Feb 8, 2023 - Mar 9, 2023.
[206] Fix | Delete
* 3. Assigned timespan dates.
[207] Fix | Delete
*
[208] Fix | Delete
* @param null|array $timespan Given timespan (dates) preferably in WP timezone.
[209] Fix | Delete
*
[210] Fix | Delete
* @since 1.8.2
[211] Fix | Delete
*
[212] Fix | Delete
* @return array
[213] Fix | Delete
*/
[214] Fix | Delete
public static function process_datepicker_choices( $timespan = null ) {
[215] Fix | Delete
[216] Fix | Delete
// Retrieve and validate timespan if none is given.
[217] Fix | Delete
if ( empty( $timespan ) || ! is_array( $timespan ) ) {
[218] Fix | Delete
$timespan = self::process_timespan();
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
list( $start_date, $end_date, $days ) = $timespan;
[222] Fix | Delete
[223] Fix | Delete
$filters = self::get_date_filter_choices();
[224] Fix | Delete
$selected = isset( $filters[ $days ] ) ? $days : 'custom';
[225] Fix | Delete
$value = self::concat_dates( $start_date, $end_date );
[226] Fix | Delete
$chosen_filter = $selected === 'custom' ? $value : $filters[ $selected ];
[227] Fix | Delete
$choices = [];
[228] Fix | Delete
[229] Fix | Delete
foreach ( $filters as $choice => $label ) {
[230] Fix | Delete
[231] Fix | Delete
$timespan_dates = self::get_timespan_dates( $choice );
[232] Fix | Delete
$checked = checked( $selected, $choice, false );
[233] Fix | Delete
$choices[] = sprintf(
[234] Fix | Delete
'<label class="%s">%s<input type="radio" aria-hidden="true" name="timespan" value="%s" %s></label>',
[235] Fix | Delete
$checked ? 'is-selected' : '',
[236] Fix | Delete
esc_html( $label ),
[237] Fix | Delete
esc_attr( self::concat_dates( ...$timespan_dates ) ),
[238] Fix | Delete
esc_attr( $checked )
[239] Fix | Delete
);
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
return [
[243] Fix | Delete
$choices,
[244] Fix | Delete
$chosen_filter,
[245] Fix | Delete
$value,
[246] Fix | Delete
];
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Based on the specified date-time range, calculates the comparable prior time period to estimate trends.
[251] Fix | Delete
*
[252] Fix | Delete
* Includes:
[253] Fix | Delete
* 1. Start date object in the given (original) timezone.
[254] Fix | Delete
* 2. End date object in the given (original) timezone.
[255] Fix | Delete
*
[256] Fix | Delete
* @since 1.8.2
[257] Fix | Delete
* @since 1.8.8 Added $days_diff optional parameter.
[258] Fix | Delete
*
[259] Fix | Delete
* @param DateTimeImmutable $start_date Start date for the timespan.
[260] Fix | Delete
* @param DateTimeImmutable $end_date End date for the timespan.
[261] Fix | Delete
* @param null|int $days_diff Optional. Number of days in the timespan. If provided, it won't be calculated.
[262] Fix | Delete
*
[263] Fix | Delete
* @return bool|array
[264] Fix | Delete
*/
[265] Fix | Delete
public static function get_prev_timespan_dates( $start_date, $end_date, $days_diff = null ) {
[266] Fix | Delete
[267] Fix | Delete
if ( ! ( $start_date instanceof DateTimeImmutable ) || ! ( $end_date instanceof DateTimeImmutable ) ) {
[268] Fix | Delete
return false;
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
// Calculate $days_diff if not provided.
[272] Fix | Delete
if ( ! is_numeric( $days_diff ) ) {
[273] Fix | Delete
$days_diff = $end_date->diff( $start_date )->format( '%a' );
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
// If $days_diff is non-positive, set $days_modifier to 1; otherwise, use $days_diff.
[277] Fix | Delete
$days_modifier = max( (int) $days_diff, 1 );
[278] Fix | Delete
[279] Fix | Delete
return [
[280] Fix | Delete
$start_date->modify( "-{$days_modifier} day" ),
[281] Fix | Delete
$start_date->modify( '-1 second' ),
[282] Fix | Delete
];
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
/**
[286] Fix | Delete
* Get the site's date format from WordPress settings and convert it to a format compatible with Moment.js.
[287] Fix | Delete
*
[288] Fix | Delete
* @since 1.8.5.4
[289] Fix | Delete
*
[290] Fix | Delete
* @return string
[291] Fix | Delete
*/
[292] Fix | Delete
public static function get_wp_date_format_for_momentjs() {
[293] Fix | Delete
[294] Fix | Delete
// Get the date format from WordPress settings.
[295] Fix | Delete
$date_format = get_option( 'date_format', 'F j, Y' );
[296] Fix | Delete
[297] Fix | Delete
// Define a mapping of PHP date format characters to Moment.js format characters.
[298] Fix | Delete
$format_mapping = [
[299] Fix | Delete
'd' => 'DD',
[300] Fix | Delete
'D' => 'ddd',
[301] Fix | Delete
'j' => 'D',
[302] Fix | Delete
'l' => 'dddd',
[303] Fix | Delete
'S' => '', // PHP's S (English ordinal suffix) is not directly supported in Moment.js.
[304] Fix | Delete
'w' => 'd',
[305] Fix | Delete
'z' => '', // PHP's z (Day of the year) is not directly supported in Moment.js.
[306] Fix | Delete
'W' => '', // PHP's W (ISO-8601 week number of year) is not directly supported in Moment.js.
[307] Fix | Delete
'F' => 'MMMM',
[308] Fix | Delete
'm' => 'MM',
[309] Fix | Delete
'M' => 'MMM',
[310] Fix | Delete
'n' => 'M',
[311] Fix | Delete
't' => '', // PHP's t (Number of days in the given month) is not directly supported in Moment.js.
[312] Fix | Delete
'L' => '', // PHP's L (Whether it's a leap year) is not directly supported in Moment.js.
[313] Fix | Delete
'o' => 'YYYY',
[314] Fix | Delete
'Y' => 'YYYY',
[315] Fix | Delete
'y' => 'YY',
[316] Fix | Delete
'a' => 'a',
[317] Fix | Delete
'A' => 'A',
[318] Fix | Delete
'B' => '', // PHP's B (Swatch Internet time) is not directly supported in Moment.js.
[319] Fix | Delete
'g' => 'h',
[320] Fix | Delete
'G' => 'H',
[321] Fix | Delete
'h' => 'hh',
[322] Fix | Delete
'H' => 'HH',
[323] Fix | Delete
'i' => 'mm',
[324] Fix | Delete
's' => 'ss',
[325] Fix | Delete
'u' => '', // PHP's u (Microseconds) is not directly supported in Moment.js.
[326] Fix | Delete
'e' => '', // PHP's e (Timezone identifier) is not directly supported in Moment.js.
[327] Fix | Delete
'I' => '', // PHP's I (Whether or not the date is in daylight saving time) is not directly supported in Moment.js.
[328] Fix | Delete
'O' => '', // PHP's O (Difference to Greenwich time (GMT) without colon) is not directly supported in Moment.js.
[329] Fix | Delete
'P' => '', // PHP's P (Difference to Greenwich time (GMT) with colon) is not directly supported in Moment.js.
[330] Fix | Delete
'T' => '', // PHP's T (Timezone abbreviation) is not directly supported in Moment.js.
[331] Fix | Delete
'Z' => '', // PHP's Z (Timezone offset in seconds) is not directly supported in Moment.js.
[332] Fix | Delete
'c' => 'YYYY-MM-DD', // PHP's c (ISO 8601 date) is not directly supported in Moment.js.
[333] Fix | Delete
'r' => 'ddd, DD MMM YYYY', // PHP's r (RFC 2822 formatted date) is not directly supported in Moment.js.
[334] Fix | Delete
'U' => '', // PHP's U (Seconds since the Unix Epoch) is not directly supported in Moment.js.
[335] Fix | Delete
];
[336] Fix | Delete
[337] Fix | Delete
// Convert PHP format to JavaScript format.
[338] Fix | Delete
$momentjs_format = strtr( $date_format, $format_mapping );
[339] Fix | Delete
[340] Fix | Delete
// Use 'MMM D, YYYY' as a fallback if the conversion is not available.
[341] Fix | Delete
return empty( $momentjs_format ) ? 'MMM D, YYYY' : $momentjs_format;
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
/**
[345] Fix | Delete
* The number of days is converted to the start and end date range.
[346] Fix | Delete
*
[347] Fix | Delete
* @since 1.8.2
[348] Fix | Delete
*
[349] Fix | Delete
* @param string $days Timespan days.
[350] Fix | Delete
*
[351] Fix | Delete
* @return array
[352] Fix | Delete
*/
[353] Fix | Delete
private static function get_timespan_dates( $days ) {
[354] Fix | Delete
[355] Fix | Delete
list( $timespan_key, $timespan_label ) = self::get_date_filter_choices( $days );
[356] Fix | Delete
[357] Fix | Delete
// Bail early, if the given number of days is NOT a number nor a numeric string.
[358] Fix | Delete
if ( ! is_numeric( $days ) ) {
[359] Fix | Delete
return [ '', '', $timespan_key, $timespan_label ];
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
$end_date = date_create_immutable( 'now', wp_timezone() );
[363] Fix | Delete
$start_date = $end_date;
[364] Fix | Delete
[365] Fix | Delete
if ( (int) $days > 0 ) {
[366] Fix | Delete
$start_date = $start_date->modify( "-{$days} day" );
[367] Fix | Delete
}
[368] Fix | Delete
[369] Fix | Delete
$start_date = $start_date->setTime( 0, 0, 0 );
[370] Fix | Delete
$end_date = $end_date->setTime( 23, 59, 59 );
[371] Fix | Delete
[372] Fix | Delete
return [
[373] Fix | Delete
$start_date, // WP timezone.
[374] Fix | Delete
$end_date, // WP timezone.
[375] Fix | Delete
$timespan_key, // i.e. 30.
[376] Fix | Delete
$timespan_label, // i.e. Last 30 days.
[377] Fix | Delete
];
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
/**
[381] Fix | Delete
* Check the delimiter to see if the end date is specified.
[382] Fix | Delete
* We can assume that the start and end dates are the same if the end date is missing.
[383] Fix | Delete
*
[384] Fix | Delete
* @since 1.8.2
[385] Fix | Delete
*
[386] Fix | Delete
* @param string $dates Given timespan (dates) in string. i.e. "2023-01-16 - 2023-02-15" or "2023-01-16".
[387] Fix | Delete
*
[388] Fix | Delete
* @return string
[389] Fix | Delete
*/
[390] Fix | Delete
private static function maybe_validate_string_timespan( $dates ) {
[391] Fix | Delete
[392] Fix | Delete
// "-" (en dash) is used as a delimiter for the datepicker module.
[393] Fix | Delete
if ( strpos( $dates, self::TIMESPAN_DELIMITER ) !== false ) {
[394] Fix | Delete
return $dates;
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
return $dates . self::TIMESPAN_DELIMITER . $dates;
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
/**
[401] Fix | Delete
* Returns a list of date filter options for the datepicker module.
[402] Fix | Delete
*
[403] Fix | Delete
* @since 1.8.2
[404] Fix | Delete
*
[405] Fix | Delete
* @param string|null $key Optional. Key associated with available filters.
[406] Fix | Delete
*
[407] Fix | Delete
* @return array
[408] Fix | Delete
*/
[409] Fix | Delete
private static function get_date_filter_choices( $key = null ) {
[410] Fix | Delete
[411] Fix | Delete
// Available date filters.
[412] Fix | Delete
$choices = [
[413] Fix | Delete
'0' => esc_html__( 'Today', 'wpforms-lite' ),
[414] Fix | Delete
'1' => esc_html__( 'Yesterday', 'wpforms-lite' ),
[415] Fix | Delete
'7' => esc_html__( 'Last 7 days', 'wpforms-lite' ),
[416] Fix | Delete
'30' => esc_html__( 'Last 30 days', 'wpforms-lite' ),
[417] Fix | Delete
'90' => esc_html__( 'Last 90 days', 'wpforms-lite' ),
[418] Fix | Delete
'365' => esc_html__( 'Last 1 year', 'wpforms-lite' ),
[419] Fix | Delete
'custom' => esc_html__( 'Custom', 'wpforms-lite' ),
[420] Fix | Delete
];
[421] Fix | Delete
[422] Fix | Delete
// Bail early, and return the full list of options.
[423] Fix | Delete
if ( is_null( $key ) ) {
[424] Fix | Delete
return $choices;
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
// Return the "Custom" filter if the given key is not found.
[428] Fix | Delete
$key = isset( $choices[ $key ] ) ? $key : 'custom';
[429] Fix | Delete
[430] Fix | Delete
return [ $key, $choices[ $key ] ];
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
/**
[434] Fix | Delete
* Concatenate given dates into a single string. i.e. "2023-01-16 - 2023-02-15".
[435] Fix | Delete
*
[436] Fix | Delete
* @since 1.8.2
[437] Fix | Delete
*
[438] Fix | Delete
* @param DateTimeImmutable $start_date Start date.
[439] Fix | Delete
* @param DateTimeImmutable $end_date End date.
[440] Fix | Delete
* @param int|string $fallback Fallback value if dates are not valid.
[441] Fix | Delete
*
[442] Fix | Delete
* @return string
[443] Fix | Delete
*/
[444] Fix | Delete
private static function concat_dates( $start_date, $end_date, $fallback = '' ) {
[445] Fix | Delete
[446] Fix | Delete
// Bail early, if the given dates are not valid.
[447] Fix | Delete
if ( ! ( $start_date instanceof DateTimeImmutable ) || ! ( $end_date instanceof DateTimeImmutable ) ) {
[448] Fix | Delete
return $fallback;
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
return implode(
[452] Fix | Delete
self::TIMESPAN_DELIMITER,
[453] Fix | Delete
[
[454] Fix | Delete
$start_date->format( self::DATE_FORMAT ),
[455] Fix | Delete
$end_date->format( self::DATE_FORMAT ),
[456] Fix | Delete
]
[457] Fix | Delete
);
[458] Fix | Delete
}
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function