diff --git a/src/classes/metadata-types/date/class-tainacan-date.php b/src/classes/metadata-types/date/class-tainacan-date.php index 015251528..e19d29593 100644 --- a/src/classes/metadata-types/date/class-tainacan-date.php +++ b/src/classes/metadata-types/date/class-tainacan-date.php @@ -48,15 +48,32 @@ class Date extends Metadata_Type { if (is_array($value)) { foreach ($value as $date_value) { $d = \DateTime::createFromFormat($format, $date_value); - if ( !($d && $d->format($format) === $date_value) ) { + if (!$d || $d->format($format) !== $value) { + $this->add_error( + sprintf( + __('Invalid date format. Expected format is YYYY-MM-DD, got %s.', 'tainacan'), + $value + ) + ); return false; } } return True; } - + $d = \DateTime::createFromFormat($format, $value); - return $d && $d->format($format) === $value; + + if (!$d || $d->format($format) !== $value) { + $this->add_error( + sprintf( + __('Invalid date format. Expected format is YYYY-MM-DD, got %s.', 'tainacan'), + $value + ) + ); + return false; + } + return true; + } /** diff --git a/src/classes/metadata-types/metadata-type/class-tainacan-metadata-type.php b/src/classes/metadata-types/metadata-type/class-tainacan-metadata-type.php index 612ac8b2b..2bc5303a6 100644 --- a/src/classes/metadata-types/metadata-type/class-tainacan-metadata-type.php +++ b/src/classes/metadata-types/metadata-type/class-tainacan-metadata-type.php @@ -153,6 +153,10 @@ abstract class Metadata_Type { public function set_description($description){ $this->description = $description; } + + public function add_error($msg) { + $this->errors[] = $msg; + } /** * @param $options