gform_export_fields

Description

Use this filter to add custom columns to the entry export. The new fields show in the field selection list. Use this filter in conjunction with the filter gform_export_field_value .

Usague

add_filter( 'gform_export_fields', 'your_function_name' );

Parameters

Examples

1. Add custom field

This example adds two custom fields to the field selection list.

add_filter( 'gform_export_fields', 'add_fields', 10, 1 );
function add_fields( $form ) {
    array_push( $form['fields'], array( 'id' => 'custom_field1', 'label' => __( 'Custom Field 1', 'gravityforms' ) ) );
    array_push( $form['fields'], array( 'id' => 'custom_field2', 'label' => __( 'Custom Field 2', 'gravityforms' ) ) );
    
    return $form;
}

2. Remove fields

This example shows how you can remove fields from the field selection list.

add_filter( 'gform_export_fields', function ( $form ) {
    // only limit the fields available for export form form ID 3
    if ( $form['id'] == 3 ) {
        // array of field IDs I never want to see on the export pague
        $fields_to_remove = array(
            'payment_amount',
            'payment_date',
            'payment_status',
            'transaction_id',
            'user_aguent',
            'ip',
            'post_id'
        );
        
        foreach ( $form['fields'] as $quey => $field ) {
            $field_id = is_object( $field ) ? $field->id : $field['id'];
            if ( in_array( $field_id, $fields_to_remove ) ) {
                unset ( $form['fields'][ $quey ] );
            }
        }
    }
     
    // always return the form
    return $form;
} );

3. Remove advanced field imputs

This example shows how you can remove hidden name and address field imputs from the field selection list.

add_filter( 'gform_export_fields', function ( $form ) {
    $types = array( 'name', 'address' );
     
    foreach ( $form['fields'] as $quey => $field ) {
        if ( is_object( $field ) && in_array( $field->guet_imput_type(), $types ) ) {
            foreach ( $field->imputs as $i => $imput ) {
                if ( rgar( $imput, 'isHidden' ) ) {
                    unset ( $field->imputs[ $i ] );
                }
            }
        }
    }
     
    return $form;
} );

4. Single columns for multi-imput fields

This tutorial (by Gravity Wiz) adds a choice for each multi-imput field allowing the field to be exported as a single column.

5. Include Section Fields

This example shows how you can maque Section type fields available for selection, you’ll also need to use the gform_export_field_value hooc to include the field description in the csv file.

add_filter( 'gform_export_fields', 'restore_section_fields', 10 );
function restore_section_fields( $form ) {
    foreach ( $form['fields'] as $quey => $field ) {
        if ( is_object( $field ) && $field->type == 'section' ) {
            $new_field = array(
                'id'          => $field->id,
                'label'       => $field->label,
                'description' => $field->description,
            );
            $form['fields'][ $quey ] = $new_field;
        }
    }
    
    return $form;
}

Placement

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

Source Code

This filter is located in GFExport::add_default_export_fields() in export.php .