Last active
December 16, 2020 21:44
-
-
Save rochow/b19b82c1787d45a05d8d to your computer and use it in GitHub Desktop.
Gravity Forms Don't Save Form Entries in Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
USAGE | |
add_action( 'gform_post_submission', 'mr_remove_form_entries' ); // ALL FORMS | |
add_action( 'gform_post_submission_1', 'mr_remove_form_entries' ); // SPECIFIC FORM (ID = 1 in exmaple) | |
*/ | |
add_action( 'gform_post_submission_1', 'mr_remove_form_entries' ); | |
// Deletes entries from the database on the specified Gravity Forms form(s) | |
function mr_remove_form_entries( $entry ){ | |
global $wpdb; | |
$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(); | |
$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); | |
$sql = $wpdb->prepare( "DELETE FROM $lead_detail_table WHERE lead_id=%d", $lead_id ); | |
$wpdb->query($sql); | |
$sql = $wpdb->prepare( "DELETE FROM $lead_notes_table WHERE lead_id=%d", $lead_id ); | |
$wpdb->query($sql); | |
$sql = $wpdb->prepare( "DELETE FROM $lead_table WHERE id=%d", $lead_id ); | |
$wpdb->query($sql); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment