Using Gravity Forms ‘gform_personal_data’ PHP filter

The gform_personal_data filter in Gravity Forms enables you to register custom data exporters and erasers with WordPress, allowing them to run during WordPress data cleanup. This hook works with the Export Personal Data and Erase Personal Data tools in WordPress.

Usage

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

Parameters

  • $custom_items (array): An array of custom export/erase functions to be run. The items in the array display on the Personal Data Settings page for selection.
  • $form (Form Object): The form object.

More information

See Gravity Forms Docs: gform_personal_data

Examples

Register Custom Data Exporter and Eraser

Register a custom data exporter and eraser with WordPress to run during data cleanup.

add_filter('gform_personal_data', 'filter_gform_personal_data', 10, 2);

function filter_gform_personal_data($items, $form) {
    $items['test'] = array(
        'label'             => 'A custom item',
        'exporter_callback' => 'gf_custom_data_exporter',
        'eraser_callback'   => 'gf_custom_data_eraser',
    );

    return $items;
}

function gf_custom_data_exporter($form, $entry) {
    $data = array(
        'name'  => 'My Custom Value',
        'value' => 'ABC123',
    );

    return $data;
}

function gf_custom_data_eraser($form, $entry) {
    // Delete or anonymize some data
}

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

Since: This filter was added in Gravity Forms 2.4.

Source Code: This filter is located in GF_Personal_Data::get_custom_items() in gravityforms/includes/class-personal-data.php.