brookedot

Prevent Entries from being saved

Mar 5th, 2013
480
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // fire the action for all forms
  2. add_action( 'gform_after_submission', 'my_remove_entries' ), 10, 2 );
  3.  
  4. // to only fire the action for a specific form, replace the "2" with the ID of your form
  5. // add_action( 'gform_post_submission_2', 'my_remove_entries', 10, 2 );
  6.  
  7. function my_remove_entries( $entry, $form ) {
  8.  
  9.     global $wpdb;
  10.  
  11.     $lead_id                = $entry['id'];
  12.     $lead_table             = RGFormsModel::get_lead_table_name();
  13.     $lead_notes_table       = RGFormsModel::get_lead_notes_table_name();
  14.     $lead_detail_table      = RGFormsModel::get_lead_details_table_name();
  15.     $lead_detail_long_table = RGFormsModel::get_lead_details_long_table_name();
  16.  
  17.     // Delete from detail long
  18.     $sql = $wpdb->prepare( " DELETE FROM $lead_detail_long_table
  19.                             WHERE lead_detail_id IN(
  20.                             SELECT id FROM $lead_detail_table WHERE lead_id=%d
  21.                             )", $lead_id );
  22.     $wpdb->query( $sql );
  23.  
  24.     // Delete from lead details
  25.     $sql = $wpdb->prepare( "DELETE FROM $lead_detail_table WHERE lead_id=%d", $lead_id );
  26.     $wpdb->query( $sql );
  27.  
  28.     // Delete from lead notes
  29.     $sql = $wpdb->prepare( "DELETE FROM $lead_notes_table WHERE lead_id=%d", $lead_id );
  30.     $wpdb->query( $sql );
  31.  
  32.     // Delete from lead
  33.     $sql = $wpdb->prepare( "DELETE FROM $lead_table WHERE id=%d", $lead_id );
  34.     $wpdb->query( $sql );
  35.  
  36. }
RAW Paste Data