Using Gravity Forms ‘gform_entry_ids_automatic_deletion’ PHP filter

The gform_entry_ids_automatic_deletion filter allows you to modify the array of entry IDs before they are automatically deleted according to the personal data retention policy.

Usage

add_filter('gform_entry_ids_automatic_deletion', 'your_function_name', 10, 1);

Parameters

  • $entry_ids (array) – The array of entry IDs to delete.

More information

See Gravity Forms Docs: gform_entry_ids_automatic_deletion

Examples

Delete only entries in Trash

The following example limits entry deletion to entries in Trash, specifically for form ID 74.

add_filter('gform_entry_ids_automatic_deletion', 'save_entries', 10, 1);

function save_entries($entry_ids){
    $delete_ids = array();
    foreach ($entry_ids as $entry_id){
        $entry = GFFormsModel::get_entry($entry_id);
        // Save entries for form ID 74 that are not in the trash
        if (!$entry['form_id'] == 74 || $entry['status'] == 'trash'){
            $delete_ids[] = $entry_id;
            GFCommon::log_debug('Deleting entry ' . $entry['id']);
        } else {
            GFCommon::log_debug('Not deleting entry ' . $entry['id']);
        }
    }
    return $delete_ids;
}

Remove one entry from the deletion list

The following example removes entry ID 99 from the list of entries to be deleted.

add_filter('gform_entry_ids_automatic_deletion', function($entry_ids) {
    GFCommon::log_debug('(): Excluding an entry from the deletion list.');

    // Remove entry ID 99 from the deletion list.
    unset($entry_ids['99']);

    return $entry_ids;
});

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

Since: This filter was added in Gravity Forms version 2.4.

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