Description
This filter allows an import file for the Chained Selects to be provided programmatically. This import file will override any previously uploaded file via the field settings.
Usage
The following would apply to all forms:
add_filter( 'gform_chainedselects_import_file', 'your_function_name', 10, 3 );
To target a specific form, append the form id to the hook name. (format: gform_chainedselects_import_file_FORMID)
add_filter( 'gform_chainedselects_import_file_14', 'your_function_name', 10, 3 );
To target a specific field id for a form, append the form id and field id to the hook name. (format: gform_chainedselects_import_file_FORMID_FIELDID)
add_filter( 'gform_chainedselects_import_file_14_2', 'your_function_name', 10, 3 );
Parameters
- $import_file array
An array of details for the file from which choices will be imported:
- $form Form Object
The form object.
-
$field Field Object
The field object.
Example
add_filter( 'gform_chainedselects_import_file', 'set_import_file', 10, 3 ); function set_import_file( $import_file, $form, $field ){ $file_array = array( 'url' => 'http://localhost/wp.dev/wp-content/plugins/gravityformschainedselects/sample.csv', 'expiration' => 60 ); return $file_array; }
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GF_Chained_Field_Select::maybe_import_from_filter() in gravityformschainedselects/includes/class-gf-field-chainedselect.php.