Skip to content

Instantly share code, notes, and snippets.

@thomasgriffin
Last active May 30, 2018 10:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomasgriffin/5368d5d28da58dd19f73 to your computer and use it in GitHub Desktop.
Save thomasgriffin/5368d5d28da58dd19f73 to your computer and use it in GitHub Desktop.
Prevent Gravity Forms from storing entries on a specific form.
<?php
add_action( 'gform_after_submission_5', 'tgm_io_remove_form_entry' );
/**
* Prevents Gravity Form entries from being stored in the database
* for a specific form. In this case, the form ID is 5. Change 5 in
* the hook to target your specific form ID.
*
* @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