SHARE
TWEET

Prevent Entries from being saved (and remove images)

brookedot Mar 6th, 2013 603 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action( 'gform_after_submission', 'nifty_gform_remove_entries ), 10, 2 );
  2. function nifty_gform_remove_entries( $entry, $form ) {
  3.            
  4.             if($form["id"] == 5){
  5.                     return;
  6.             }
  7.    
  8.            global $wpdb;
  9.    
  10.            $lead_id                = $entry['id'];
  11.            $lead_table             = RGFormsModel::get_lead_table_name();
  12.            $lead_notes_table       = RGFormsModel::get_lead_notes_table_name();
  13.            $lead_detail_table      = RGFormsModel::get_lead_details_table_name();
  14.            $lead_detail_long_table = RGFormsModel::get_lead_details_long_table_name();
  15.    
  16.            // Delete from detail long
  17.            $sql = $wpdb->prepare( " DELETE FROM $lead_detail_long_table
  18.                                                            WHERE lead_detail_id IN(
  19.                                                            SELECT id FROM $lead_detail_table WHERE lead_id=%d
  20.                                                            )", $lead_id );
  21.            $wpdb->query( $sql );
  22.    
  23.           // Remove file uploads
  24.           $sql = $wpdb->prepare("SELECT value FROM $lead_detail_table WHERE lead_id=%d", $lead_id );
  25.           $results = $wpdb->get_results($sql, ARRAY_A ) or die(mysql_error());
  26.            foreach ($results as $check_value_for_file) {
  27.                 $file_url = parse_url($check_value_for_file['value']);
  28.                 $file_path = $file_url['path'];
  29.                 $upload_dir = wp_upload_dir();
  30.                 $file_location = realpath($upload_dir['basedir']. "/../../").$file_path;
  31.                 if (file_exists($file_location)) {
  32.                         unlink($file_location);    
  33.                 }
  34.            }
  35.            
  36.            // Delete from lead details
  37.            $sql = $wpdb->prepare( "DELETE FROM $lead_detail_table WHERE lead_id=%d", $lead_id );
  38.            $wpdb->query( $sql );
  39.            
  40.            
  41.    
  42.            // Delete from lead notes
  43.            $sql = $wpdb->prepare( "DELETE FROM $lead_notes_table WHERE lead_id=%d", $lead_id );
  44.            $wpdb->query( $sql );
  45.    
  46.            // Delete from lead
  47.            $sql = $wpdb->prepare( "DELETE FROM $lead_table WHERE id=%d", $lead_id );
  48.            $wpdb->query( $sql );
  49.    
  50.    }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top