gform_field_filters

Description

The “gform_field_filters” filter in Gravity Forms enables the filter settings to be overridden for the 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.

Examples

1. Add a custom payment status

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;
}

2. Add an operator to a specific field

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