If you look in the validation function you will find that the year is hardcoded to 1980 minimum.
I’ve added in support for the total_years
option that it already has but wasn’t using here.
I also added in two nice extra features. It checks if the date is past today, and also correctly validates the days in the month, depending on the selected month and year:
public function validate_value($valid, $value, $field, $input)
{
if (empty($value)
|| empty($value["date_month"])
|| empty($value["date_day"])
|| empty($value["date_year"])
) {
return false;
}
$year = intval($value["date_year"]);
$month = intval($value["date_month"]);
$day = intval($value["date_day"]);
if ($month < 1 || $month > 12) {
return "Invalid Month";
}
$days_in_month = cal_days_in_month(CAL_GREGORIAN, $month, $year);
if ($day < 1 || $day > $days_in_month) {
return "Invalid Day";
}
$current_year = date("Y");
$minimum_year = $current_year - intval($field['total_years']);
if ($year < $minimum_year || $year > $current_year) {
return "Invalid Year";
}
// check not in future
$selected_date = new DateTime("$year-$month-$day");
if($selected_date > new DateTime()) {
return "Date is in the future.";
}
// return
return $valid;
}
Note: if the author reads this and wants to, please do incorporate this fix into the plugin.
]]>In render_field_settings($field)
.
Set required to true otherwise it will allow empty values and break the code elsewhere.
acf_render_field_setting($field, array(
'label' => __('Total Years', 'acf'),
'instructions' => '',
'name' => 'total_years',
'type' => 'number',
'min' => 1,
'max' => 999,
'required' => true,
));
]]>