Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict to convert meta value into date if year is greater than 2099 #2828

Merged
merged 3 commits into from
Jun 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion includes/classes/Indexable.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,24 @@ public function prepare_date_meta_values( $meta_types, $meta_value ) {
if ( $new_date ) {
$timestamp = $new_date->getTimestamp();

/**
* Filter the maximum year limit for date conversion.
*
* Use default date if year is greater than max limit. EP has limitation that doesn't allow to have year greater than 2099.
*
* @see https://github.com/10up/ElasticPress/issues/2769
*
* @hook ep_max_year_limit
* @param {int} $year Maximum year limit.
* @return {int} Maximum year limit.
* @since 4.2.1
*/
$max_year = apply_filters( 'ep_max_year_limit', 2099 );

// PHP allows DateTime to build dates with the non-existing year 0000, and this causes
// issues when integrating into stricter systems. This is by design:
// https://bugs.php.net/bug.php?id=60288
if ( false !== $timestamp && '0000' !== $new_date->format( 'Y' ) ) {
if ( false !== $timestamp && '0000' !== $new_date->format( 'Y' ) && $new_date->format( 'Y' ) <= $max_year ) {
$meta_types['date'] = $new_date->format( 'Y-m-d' );
$meta_types['datetime'] = $new_date->format( 'Y-m-d H:i:s' );
$meta_types['time'] = $new_date->format( 'H:i:s' );
Expand Down