gform_export_fields

gform_export_fields

DescriptionUsageParametersExamples1. Add custom field2. Remove fields3. Remove advanced field inputs4. Single columns for multi-input fields5. Include Section FieldsPlacementSource Code

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.
Usage
1add_filter( 'gform_export_fields', 'your_function_name' );

Parameters

$form Form Object
The current form.

Examples
1. Add custom field
This example adds two custom fields to the field selection list.
1234567add_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.
12345678910111213141516171819202122232425add_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 page        $fields_to_remove = array(            'payment_amount',            'payment_date',            'payment_status',            'transaction_id',            'user_agent',            'ip',            'post_id'        );         foreach ( $form['fields'] as $key => $field ) {            $field_id = is_object( $field ) ? $field->id : $field['id'];            if ( in_array( $field_id, $fields_to_remove ) ) {                unset ( $form['fields'][ $key ] );            }        }    }     // always return the form    return $form;} );
3. Remove advanced field inputs
This example shows how you can remove hidden name and address field inputs from the field selection list.
12345678910111213141516add_filter( 'gform_export_fields', function ( $form ) {    $types = array( 'name', 'address' );     foreach ( $form['fields'] as $key => $field ) {        if ( is_object( $field ) && in_array( $field->get_input_type(), $types ) ) {            foreach ( $field->inputs as $i => $input ) {                if ( rgar( $input, 'isHidden' ) ) {                    unset ( $field->inputs[ $i ] );                }            }        }     }     return $form;} );
4. Single columns for multi-input fields
This tutorial (by Gravity Wiz) adds a choice for each multi-input field allowing the field to be exported as a single column.
5. Include Section Fields
This example shows how you can make Section type fields available for selection, you』ll also need to use the gform_export_field_value hook to include the field description in the csv file.
123456789101112131415add_filter( 'gform_export_fields', 'restore_section_fields', 10 );function restore_section_fields( $form ) {    foreach ( $form['fields'] as $key => $field ) {        if ( is_object( $field ) && $field->type == 'section' ) {            $new_field = array(                'id'          => $field->id,                'label'       => $field->label,                'description' => $field->description,            );            $form['fields'][ $key ] = $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.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注