gform_date_max_year

gform_date_max_year

DescriptionUsageParametersExamplesPlacementSource Code

Description
Use this filter to specify the maximum year displayed in the date field』s year drop down and the HTML5 max attribute for the date field』s year input.
Usage
add_filter( 'gform_date_max_year' , 'set_max_year' );

Parameters

$max_date string
The maximum date to be filtered. Defaults to the current year plus one.

$form Form Object
Current form object.

$field Field Object
Current field object.

Examples
This example changes the max date to 2022.
add_filter( 'gform_date_max_year', 'set_max_year' );
function set_max_year( $max_year ) {
return 2022;
}

This example changes the max date for a specific field on a specific form.
add_filter( 'gform_date_max_year', function ( $max_year, $form, $field ) {

return $form['id'] == 7 && $field->id == 5 ? 2022 : $max_year;
}, 10, 3 );

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods in includes/fields/class-gf-field-date.php:

GF_Field_Date::get_field_input()
GF_Field_Date::get_year_dropdown()

發表回覆

您的郵箱地址不會被公開。 必填項已用 * 標註