Using Gravity Forms ‘gform_field_filters’ PHP filter

The gform_field_filters filter in Gravity Forms allows you to override filter settings for form fields, entry properties, and entry meta.

Usage

add_filter('gform_field_filters', 'your_function_name', 10, 2);

Parameters

  • $field_filters (array): The form field, entry properties, and entry meta filter settings.
  • $form (Form Object): The form object.

More information

See Gravity Forms Docs: gform_field_filters

Examples

Add a custom payment status

Add a custom payment status to the payment status filter options.

add_filter('gform_field_filters', 'update_filters', 10, 2);
function update_filters($field_filters, $form) {
    foreach ($field_filters as &$filter) {
        if ($filter['key'] == 'payment_status') {
            // Add custom payment status
            $values = $filter['values'];
            $status_exists = false;
            foreach ($values as &$value) {
                if ($value['text'] == 'Test Status') {
                    $status_exists = true;
                }
            }
            if (!$status_exists) {
                // Add status
                array_push($values, array('text' => 'Test Status', 'value' => 'Test Status'));
                $filter['values'] = $values;
            }
        }
    }
    return $field_filters;
}

Add an operator to a specific field

Add a new operator “isnot” to field ID 2.

add_filter('gform_field_filters', function ($field_filters, $form) {
    foreach ($field_filters as $filter) {
        if (rgar($filter, 'key') == '2') {
            $filter['operators'][] = 'isnot';
            break;
        }
    }
    return $field_filters;
}, 10, 2);

Placement

This code should be placed in the functions.php file of your active theme.

Since

This filter was added in Gravity Forms 2.3.1.16.

Source Code

This filter is located in GFCommon::get_field_filter_settings() in common.php.