Using Gravity Forms ‘gform_import_form_xml_options’ PHP filter

The gform_import_form_xml_options filter allows you to modify the settings used to import a form from an XML export file. This is particularly useful when adding your own field types with custom settings stored as an array.

Usage

add_filter('gform_import_form_xml_options', 'my_custom_function');

Parameters

  • $options (array): Array of options for the XML import.

More information

See Gravity Forms Docs: gform_import_form_xml_options

Examples

Specifying custom form setting to unserialize as an array

This example demonstrates how to specify that a custom form setting should be unserialized as an array (rather than an object). This assumes that the setting is created in an array format. When the form is exported to XML, it will no longer be in array format, so on import, we need to specify how it should be formatted.

add_filter('gform_import_form_xml_options', 'my_custom_import_xml_options');

function my_custom_import_xml_options($options) {
    $options['my_custom_form_setting'] = array('unserialize_as_array' => true);
    return $options;
}

Adding a custom option for import

In this example, we add a custom option to handle importing a new field type.

add_filter('gform_import_form_xml_options', 'import_custom_field_type');

function import_custom_field_type($options) {
    $options['custom_field_type'] = array('unserialize_as_array' => true);
    return $options;
}

Modifying an existing option

This example shows how to modify an existing option for the import process.

add_filter('gform_import_form_xml_options', 'modify_existing_option');

function modify_existing_option($options) {
    $options['existing_option'] = array('unserialize_as_array' => false);
    return $options;
}

Removing an option

This example demonstrates how to remove an option from the import process.

add_filter('gform_import_form_xml_options', 'remove_unneeded_option');

function remove_unneeded_option($options) {
    unset($options['unneeded_option']);
    return $options;
}

Adding multiple custom options

In this example, we add multiple custom options for handling the import of different custom field types.

add_filter('gform_import_form_xml_options', 'import_multiple_custom_field_types');

function import_multiple_custom_field_types($options) {
    $options['custom_field_type_1'] = array('unserialize_as_array' => true);
    $options['custom_field_type_2'] = array('unserialize_as_array' => false);
    return $options;
}