GravityExport Developer Hooks
These are the developer hooks available GravityKit Lite and GravityExport. All code is provided as examples and should be tested before being used. See how to add custom PHP to your site.
Most hooks use gf_apply_filters() , so they are also available with _{form_id} added to the filter name (example: gfexcel_renderer_matrix_{form_id}). Using the form filters will only modify values associated with that specific form.
gfexcel_renderer_matrix
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Modify the export matrix before it's rendered. The matrix is a two-dimensional array containing header row and all entry data rows.
| Property | Type | Default | Description |
|---|---|---|---|
$matrix |
array |
N/A | Two-dimensional array with row 0 as header, rows 1+ as data |
$form |
array |
N/A | Gravity Forms form object |
Matrix Structure
The matrix is a two-dimensional array where:
- Row 0 (Header): Contains column header objects (
GFExcel\Values\StringValue) - Row 1+ (Data): Contains entry data as value objects
Each cell in the matrix is an implementation of the GFExcel\Values\BaseValue object, for example:
GFExcel\Values\StringValue- Text valuesGFExcel\Values\NumericValue- Numeric values (Entry ID, User ID, etc.)
Value Object Properties
All value objects extend from a base class and include:
| Property | Type | Access | Description |
|---|---|---|---|
value |
mixed |
protected |
The actual cell value |
gf_field |
GF_Field |
protected |
Associated Gravity Forms field object |
is_numeric |
bool |
protected |
Whether value should be formatted as number |
color |
string |
protected |
Text color |
background_color |
string |
protected |
Cell background color |
is_bold |
bool |
protected |
Bold formatting |
is_italic |
bool |
protected |
Italic formatting |
url |
string |
protected |
Hyperlink URL |
Removing columns with only empty values
This code filters out columns from being included in the export where all the values in the column are empty.
/**
* Remove empty columns from the matrix.
*
* Filters out columns where all values (excluding the header) are empty.
*
* @since 1.0.0
*
* @param array $matrix The matrix containing all rows and columns. First row is the header.
* @param array $form The form object (unused; required by filter signature).
*
* @return array The matrix with empty columns removed.
*/
function gfexcel_remove_empty_columns( $matrix, $form ) {
if ( empty( $matrix ) || count( $matrix ) < 2 ) {
return $matrix; // Need header + at least one data row.
}
/**
* Determine whether a cell value should be considered empty.
*
* Preserves 0, '0', 0.0, and false as non-empty.
*
* @param mixed $value The value to check.
* @return bool
*/
$is_empty = static function( $value ): bool {
// Unwrap GFExcel value objects.
if ( is_object( $value ) && method_exists( $value, 'getValue' ) ) {
$value = $value->getValue();
}
// Empty arrays are empty; non-empty arrays are not.
if ( is_array( $value ) ) {
return count( $value ) === 0;
}
if ( is_string( $value ) ) {
return '' === trim( $value );
}
return $value === null || $value === '';
};
$data_rows = array_slice( $matrix, 1 );
$column_count = count( $matrix[0] );
$columns_to_keep = [];
// Find columns with at least one non-empty value.
for ( $col_index = 0; $col_index < $column_count; $col_index++ ) {
foreach ( $data_rows as $row ) {
$val = $row[ $col_index ] ?? null;
if ( ! $is_empty( $val ) ) {
$columns_to_keep[] = $col_index;
continue 2; // Skip to next column.
}
}
}
// Rebuild matrix keeping only non-empty columns.
if ( empty( $columns_to_keep ) ) {
// All columns empty: return empty rows with no columns.
return array_fill( 0, count( $matrix ), [] );
}
$keep_flip = array_flip( $columns_to_keep );
return array_map(
static function( $row ) use ( $keep_flip ) {
return array_values( array_intersect_key( $row, $keep_flip ) );
},
$matrix
);
}
add_filter( 'gfexcel_renderer_matrix', 'gfexcel_remove_empty_columns', 10, 2 );
Removing the header row
If you want to remove the header row from GravityKit export, add this code to your site. This will remove the first row.
/**
* Remove the values from the first row of the matrix. The columns still exist, but the values are empty. This removes the first (header) row.
* @param mixed[] $matrix The matrix containing all rows and columns.
* @return mixed[] The matrix containing all rows and columns.
*/
add_filter( 'gfexcel_renderer_matrix', function( $matrix ) {
unset( $matrix[0] ); // Unset the first row. Doesn't remove the row, only the values.
return array_values( $matrix ); // Re-indexes the array to start at 0, removing the first row.
}, 10, 1 );
gfexcel_renderer_hide_row
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Hide specific rows from the export based on custom logic.
| Property | Type | Default | Description |
|---|---|---|---|
$hide |
bool |
false |
Whether to hide the row |
$row |
array |
N/A | Array of cell values for the current row |
$form_id |
int |
N/A | The form ID |
Sample code
/**
* Hide rows where field 1 is empty.
*
* @param bool $hide Whether to hide the row.
* @param array $row The row data.
* @param int $form_id The form ID.
* @return bool True to hide the row.
*/
function gravityexport_hide_empty_field_rows( $hide, $row, $form_id ) {
foreach ( $row as $column ) {
if ( 1 === $column->getFieldId() && empty( $column->getValue() ) ) {
return true;
}
}
return $hide;
}
add_filter( 'gfexcel_renderer_hide_row', 'gravityexport_hide_empty_field_rows', 10, 3 );
gfexcel_renderer_columns_max_width
Applies to: Excel (.xlsx), PDF (.pdf)
Set the maximum width for auto-sized columns in the export.
| Property | Type | Default | Description |
|---|---|---|---|
$max_width |
int|null |
null |
Maximum column width in Excel units (null = no limit) |
Sample code
/**
* Limit column width to 50 units.
*
* @param int|null $max_width The maximum column width.
* @return int The new maximum width.
*/
function gravityexport_set_max_column_width( $max_width ) {
return 50;
}
add_filter( 'gfexcel_renderer_columns_max_width', 'gravityexport_set_max_column_width' );
gfexcel_renderer_wrap_text
Applies to: Excel (.xlsx), PDF (.pdf)
Control whether cell text should wrap.
| Property | Type | Default | Description |
|---|---|---|---|
$wrap_text |
bool |
true |
Whether to wrap text in cells |
$cell |
Cell |
N/A | PhpSpreadsheet Cell object |
$value |
BaseValue|mixed |
N/A | The cell value object or raw value |
$form_id |
int |
N/A | The form ID |
Sample code
/**
* Disable text wrapping for all cells.
*
* @param bool $wrap_text Whether to wrap text.
* @param Cell $cell The cell object.
* @param mixed $value The cell value.
* @param int $form_id The form ID.
* @return bool False to disable text wrapping.
*/
function gravityexport_disable_text_wrap( $wrap_text, $cell, $value, $form_id ) {
return false;
}
add_filter( 'gfexcel_renderer_wrap_text', 'gravityexport_disable_text_wrap', 10, 4 );
gfexcel_renderer_worksheet_title
Applies to: Excel (.xlsx), PDF (.pdf)
Customize the worksheet/tab name in the Excel file, or the document title in PDF exports.
| Property | Type | Default | Description |
|---|---|---|---|
$title |
string |
Form title | Worksheet title (max 30 characters) |
$form |
array |
N/A | The form object |
$form_id |
int |
N/A | The form ID |
Sample code
/**
* Add form ID to worksheet title.
*
* @param string $title The worksheet title.
* @param array $form The form object.
* @param int $form_id The form ID.
* @return string Modified worksheet title.
*/
function gravityexport_custom_worksheet_title( $title, $form, $form_id ) {
return sprintf( 'Form %d - %s', $form_id, $title );
}
add_filter( 'gfexcel_renderer_worksheet_title', 'gravityexport_custom_worksheet_title', 10, 3 );
gfexcel_renderer_disable_hyperlinks
Applies to: Excel (.xlsx), PDF (.pdf)
Disable hyperlinks in the export globally.
| Property | Type | Default | Description |
|---|---|---|---|
$disable |
bool |
false |
Whether to disable all hyperlinks |
Sample code
/** * Disable all hyperlinks in export. * * @return bool True to disable hyperlinks. */ add_filter( 'gfexcel_renderer_disable_hyperlinks', '__return_true' );
gfexcel_output_rows
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Modify the rows before they're processed into the matrix.
| Property | Type | Default | Description |
|---|---|---|---|
$rows |
array |
N/A | Array of entry rows |
$form |
array |
N/A | The form object |
$form_id |
int |
N/A | The form ID |
Sample code
/**
* Filter out test entries from export.
*
* @param array $rows The entry rows.
* @param array $form The form object.
* @param int $form_id The form ID.
* @return array Filtered rows.
*/
function gravityexport_remove_test_entries( $rows, $form, $form_id ) {
return array_filter( $rows, function( $row ) {
// Remove entries with "test" in field 1
return false === stripos( $row[1], 'test' );
} );
}
add_filter( 'gfexcel_output_rows', 'gravityexport_remove_test_entries', 10, 3 );
gfexcel_output_columns
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Modify which columns are included in the export.
| Property | Type | Default | Description |
|---|---|---|---|
$columns |
array |
N/A | Array of column field objects |
$form |
array |
N/A | The form object |
$form_id |
int |
N/A | The form ID |
Sample code
/**
* Remove specific columns from export.
*
* @param array $columns The column fields.
* @param array $form The form object.
* @param int $form_id The form ID.
* @return array Modified columns.
*/
function gravityexport_remove_admin_columns( $columns, $form, $form_id ) {
return array_filter( $columns, function( $column ) {
// Remove admin-only fields
return ! in_array( $column->id, [ 'ip', 'user_agent' ], true );
} );
}
add_filter( 'gfexcel_output_columns', 'gravityexport_remove_admin_columns', 10, 3 );
gfexcel_output_search_criteria
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Modify the search criteria used to fetch entries for export.
| Property | Type | Default | Description |
|---|---|---|---|
$search_criteria |
array |
['status' => 'active'] |
GFAPI search criteria array |
$form_id |
int |
N/A | The form ID |
$feed_id |
int |
N/A | The feed ID (if applicable) |
Sample code
/**
* Only export entries from last 30 days.
*
* @param array $search_criteria The search criteria.
* @param int $form_id The form ID.
* @param int $feed_id The feed ID.
* @return array Modified search criteria.
*/
function gravityexport_last_30_days( $search_criteria, $form_id, $feed_id ) {
$search_criteria['start_date'] = date( 'Y-m-d', strtotime( '-30 days' ) );
$search_criteria['end_date'] = date( 'Y-m-d' );
return $search_criteria;
}
add_filter( 'gfexcel_output_search_criteria', 'gravityexport_last_30_days', 10, 3 );
gfexcel_output_sorting_options
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Customize how entries are sorted in the export.
| Property | Type | Default | Description |
|---|---|---|---|
$sorting |
array |
['key' => 'date_created', 'direction' => 'ASC'] |
Sorting configuration |
$form_id |
int |
N/A | The form ID |
$feed_id |
int |
N/A | The feed ID (if applicable) |
Sample code
/**
* Sort by entry ID descending.
*
* @param array $sorting The sorting options.
* @param int $form_id The form ID.
* @param int $feed_id The feed ID.
* @return array Modified sorting options.
*/
function gravityexport_sort_by_id_desc( $sorting, $form_id, $feed_id ) {
return [
'key' => 'id',
'direction' => 'DESC',
];
}
add_filter( 'gfexcel_output_sorting_options', 'gravityexport_sort_by_id_desc', 10, 3 );
gfexcel_field_checkbox_empty
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Define the value to use for empty checkbox fields.
| Property | Type | Default | Description |
|---|---|---|---|
$empty_value |
string |
'' |
Value to use for unchecked checkboxes |
$field |
GF_Field |
N/A | The checkbox field object |
$form_id |
int |
N/A | The form ID |
Sample code
/**
* Use "No" for empty checkboxes.
*
* @param string $empty_value The empty value.
* @param GF_Field $field The field object.
* @param int $form_id The form ID.
* @return string The new empty value.
*/
function gravityexport_checkbox_empty_no( $empty_value, $field, $form_id ) {
return 'No';
}
add_filter( 'gfexcel_field_checkbox_empty', 'gravityexport_checkbox_empty_no', 10, 3 );
gfexcel_field_date_format
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Customize the date format for date fields in the export.
| Property | Type | Default | Description |
|---|---|---|---|
$format |
string |
Field format | PHP date format string |
$field |
GF_Field |
N/A | The date field object |
$form_id |
int |
N/A | The form ID |
$input_id |
string |
N/A | The input ID (for multi-input fields) |
Sample code
/**
* Use ISO 8601 date format.
*
* @param string $format The date format.
* @param GF_Field $field The field object.
* @param int $form_id The form ID.
* @param string $input_id The input ID.
* @return string The new date format.
*/
function gravityexport_iso_date_format( $format, $field, $form_id, $input_id ) {
return 'Y-m-d';
}
add_filter( 'gfexcel_field_date_format', 'gravityexport_iso_date_format', 10, 4 );
gfexcel_combiner_glue
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Customize the separator used when combining multi-value fields.
| Property | Type | Default | Description |
|---|---|---|---|
$glue |
string |
', ' |
String used to join multiple values |
$field_type |
string |
N/A | The field type (e.g., 'checkbox', 'multiselect') |
$field_id |
int |
N/A | The field ID |
$form_id |
int |
N/A | The form ID |
Sample code
/**
* Use semicolon separator for checkbox fields.
*
* @param string $glue The separator string.
* @param string $field_type The field type.
* @param int $field_id The field ID.
* @param int $form_id The form ID.
* @return string The new separator.
*/
function gravityexport_semicolon_separator( $glue, $field_type, $field_id, $form_id ) {
if ( 'checkbox' === $field_type ) {
return '; ';
}
return $glue;
}
add_filter( 'gfexcel_combiner_glue', 'gravityexport_semicolon_separator', 10, 4 );
gfexcel_file_extension
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Set the file extension/format for a specific form's exports.
| Property | Type | Default | Description |
|---|---|---|---|
$extension |
string |
'xlsx' |
File extension ('xlsx', 'csv', or 'pdf') |
$form |
array |
N/A | The form object |
Sample code
/**
* Use CSV format for form ID 5.
*
* @param string $extension The file extension.
* @param array $form The form object.
* @return string The file extension.
*/
function gravityexport_csv_for_form_5( $extension, $form ) {
if ( 5 === (int) rgar( $form, 'id' ) ) {
return 'csv';
}
return $extension;
}
add_filter( 'gfexcel_file_extension', 'gravityexport_csv_for_form_5', 10, 2 );
gfexcel_file_extensions
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Register available file format extensions that the plugin recognizes.
| Property | Type | Default | Description |
|---|---|---|---|
$extensions |
array |
['xlsx', 'csv'] |
Array of supported extensions |
Sample code
/**
* Add custom export format.
*
* @param array $extensions Supported extensions.
* @return array Modified extensions array.
*/
function gravityexport_add_custom_format( $extensions ) {
$extensions[] = 'ods'; // OpenDocument Spreadsheet
return $extensions;
}
add_filter( 'gfexcel_file_extensions', 'gravityexport_add_custom_format' );
CSV-Specific Filters
The following filters only apply to CSV (.csv) exports.
gfexcel_renderer_csv_delimiter
Applies to: CSV (.csv) only
Set the CSV delimiter character.
| Property | Type | Default | Description |
|---|---|---|---|
$delimiter |
string |
',' |
CSV delimiter character |
$form_id |
int |
N/A | The form ID |
Sample code
/**
* Use semicolon delimiter for CSV.
*
* @param string $delimiter The delimiter.
* @param int $form_id The form ID.
* @return string The new delimiter.
*/
function gravityexport_semicolon_delimiter( $delimiter, $form_id ) {
return ';';
}
add_filter( 'gfexcel_renderer_csv_delimiter', 'gravityexport_semicolon_delimiter', 10, 2 );
gfexcel_renderer_csv_enclosure
Applies to: CSV (.csv) only
Set the CSV enclosure character.
| Property | Type | Default | Description |
|---|---|---|---|
$enclosure |
string |
'"' |
CSV enclosure character |
$form_id |
int |
N/A | The form ID |
gfexcel_renderer_csv_line_ending
Applies to: CSV (.csv) only
Set the CSV line ending character(s).
| Property | Type | Default | Description |
|---|---|---|---|
$line_ending |
string |
"\r\n" |
CSV line ending |
$form_id |
int |
N/A | The form ID |
gfexcel_renderer_csv_use_bom
Applies to: CSV (.csv) only
Control whether to include BOM (Byte Order Mark) in CSV.
| Property | Type | Default | Description |
|---|---|---|---|
$use_bom |
bool |
false |
Whether to include UTF-8 BOM |
$form_id |
int |
N/A | The form ID |
Sample code
/**
* Add UTF-8 BOM for Excel compatibility.
*
* @param bool $use_bom Whether to use BOM.
* @param int $form_id The form ID.
* @return bool True to include BOM.
*/
function gravityexport_enable_bom( $use_bom, $form_id ) {
return true;
}
add_filter( 'gfexcel_renderer_csv_use_bom', 'gravityexport_enable_bom', 10, 2 );
gfexcel_renderer_csv_include_separator_line
Applies to: CSV (.csv) only
Include a separator line at the top of CSV files.
| Property | Type | Default | Description |
|---|---|---|---|
$include |
bool |
false |
Whether to include separator line |
$form_id |
int |
N/A | The form ID |
gfexcel_renderer_csv_output_encoding
Applies to: CSV (.csv) only
Set the CSV output encoding.
| Property | Type | Default | Description |
|---|---|---|---|
$encoding |
string |
'UTF-8' |
Output encoding |
$form_id |
int |
N/A | The form ID |
Advanced Filters
gfexcel_value_type
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Change the value object class used to render a specific field's data.
| Property | Type | Default | Description |
|---|---|---|---|
$type |
string |
Field-dependent | Value class name (e.g., 'StringValue', 'NumericValue') |
$field_type |
string |
N/A | The field input type |
$form_id |
int |
N/A | The form ID |
$field_id |
int |
N/A | The field ID |
$gf_field |
GF_Field |
N/A | The field object |
$is_label |
bool |
false |
Whether this value object is for a label |
gfexcel_field_separated
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Control whether a field should be split into separate columns (applies to Name, Address, and similar multi-part fields).
| Property | Type | Default | Description |
|---|---|---|---|
$separated |
bool |
Settings-dependent | Whether to separate into multiple columns |
$field_type |
string |
N/A | The field input type (e.g., 'name', 'address') |
$form_id |
int |
N/A | The form ID |
$field_id |
int |
N/A | The field ID |
$field |
GF_Field |
N/A | The field object |
Sample code
/**
* Keep name field as single column.
*
* @param bool $separated Whether to separate.
* @param string $field_type The field input type.
* @param int $form_id The form ID.
* @param int $field_id The field ID.
* @param GF_Field $field The field object.
* @return bool False to keep as single column.
*/
function gravityexport_single_name_column( $separated, $field_type, $form_id, $field_id, $field ) {
if ( 'name' === $field_type ) {
return false;
}
return $separated;
}
add_filter( 'gfexcel_field_separated', 'gravityexport_single_name_column', 10, 5 );
gfexcel_field_label
Applies to: Excel (.xlsx), CSV (.csv), PDF (.pdf)
Customize field labels (column headers) in the export.
| Property | Type | Default | Description |
|---|---|---|---|
$label |
string |
Field label | The column header label |
$field_type |
string |
N/A | The field input type |
$form_id |
int |
N/A | The form ID |
$field_id |
int |
N/A | The field ID |
$field |
GF_Field |
N/A | The field object |
Sample code
/**
* Add field ID to column headers.
*
* @param string $label The field label.
* @param string $field_type The field input type.
* @param int $form_id The form ID.
* @param int $field_id The field ID.
* @param GF_Field $field The field object.
* @return string Modified label.
*/
function gravityexport_add_id_to_label( $label, $field_type, $form_id, $field_id, $field ) {
return sprintf( '%s (ID: %d)', $label, $field_id );
}
add_filter( 'gfexcel_field_label', 'gravityexport_add_id_to_label', 10, 5 );
Actions
gfexcel_renderer_cell_properties
Applies to: Excel (.xlsx), PDF (.pdf)
Modify cell properties directly using PhpSpreadsheet API.
| Property | Type | Description |
|---|---|---|
$cell |
Cell |
PhpSpreadsheet Cell object |
$value |
BaseValue|mixed |
The cell value object or raw value |
$form_id |
int |
The form ID |
Sample code
/**
* Make header row bold with background color.
*
* @param Cell $cell The cell object.
* @param mixed $value The cell value.
* @param int $form_id The form ID.
*/
function gravityexport_style_header_row( $cell, $value, $form_id ) {
if ( 1 !== $cell->getRow() ) {
return;
}
$cell->getStyle()->getFont()->setBold( true );
$cell->getStyle()->getFill()
->setFillType( \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID )
->getStartColor()->setRGB( 'CCCCCC' );
}
add_action( 'gfexcel_renderer_cell_properties', 'gravityexport_style_header_row', 10, 3 );