Skip to content

Instantly share code, notes, and snippets.

@thomasgriffin
Last active February 13, 2017 19:05
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasgriffin/3fc79ee983329bd6c528 to your computer and use it in GitHub Desktop.
Save thomasgriffin/3fc79ee983329bd6c528 to your computer and use it in GitHub Desktop.
Prevent Gravity Forms from storing entries in the database.
<?php
add_action( 'gform_after_submission', 'tgm_io_remove_form_entry' );
/**
* Prevents Gravity Form entries from being stored in the database.
*
* @global object $wpdb The WP database object.
* @param array $entry Array of entry data.
*/
function tgm_io_remove_form_entry( $entry ) {
global $wpdb;
// Prepare variables.
$lead_id = $entry['id'];
$lead_table = RGFormsModel::get_lead_table_name();
$lead_notes_table = RGFormsModel::get_lead_notes_table_name();
$lead_detail_table = RGFormsModel::get_lead_details_table_name();
$lead_detail_long_table = RGFormsModel::get_lead_details_long_table_name();
// Delete from lead detail long.
$sql = $wpdb->prepare( "DELETE FROM $lead_detail_long_table WHERE lead_detail_id IN(SELECT id FROM $lead_detail_table WHERE lead_id = %d)", $lead_id );
$wpdb->query( $sql );
// Delete from lead details.
$sql = $wpdb->prepare( "DELETE FROM $lead_detail_table WHERE lead_id = %d", $lead_id );
$wpdb->query( $sql );
// Delete from lead notes.
$sql = $wpdb->prepare( "DELETE FROM $lead_notes_table WHERE lead_id = %d", $lead_id );
$wpdb->query( $sql );
// Delete from lead.
$sql = $wpdb->prepare( "DELETE FROM $lead_table WHERE id = %d", $lead_id );
$wpdb->query( $sql );
// Finally, ensure everything is deleted (like stuff from Addons).
GFAPI::delete_entry( $lead_id );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment