Extracts validation error msg

This commit is contained in:
Rodrigo de Oliveira 2021-04-04 23:38:59 -03:00
parent 55afa4567c
commit 3ea5c2134b
1 changed files with 11 additions and 14 deletions

View File

@ -35,31 +35,21 @@ class Date extends Metadata_Type {
foreach ($value as $date_value) {
$d = \DateTime::createFromFormat($format, $date_value);
if (!$d || $d->format($format) !== $date_value) {
$this->add_error(
sprintf(
__('Invalid date format. Expected format is YYYY-MM-DD, got %s.', 'tainacan'),
$date_value
)
);
$this->add_error($this->format_error_msg($date_value));
return false;
}
}
return True;
return true;
}
$d = \DateTime::createFromFormat($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
)
);
$this->add_error($this->format_error_msg($value));
return false;
}
return true;
}
/**
@ -99,4 +89,11 @@ class Date extends Metadata_Type {
return mysql2date(get_option('date_format'), ($value));
}
private function format_error_msg($value) {
return sprintf(
__('Invalid date format. Expected format is YYYY-MM-DD, got %s.', 'tainacan'),
$value
);
}
}