Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Check all of our Entries that have been created.
- * If they are 24 hours old & Payment Status is
- * processing then we will delete them, and automatically
- * re-open our Gravity Form.
- *
- * Dan Gavin
- */
- function gf_published_entry_time( $entry, $form ) {
- global $wpdb;
- // Get all Entries for our form ID 1
- $entries = RGFormsModel::get_leads(1, '', 'DESC', '', '0', '99999999');
- foreach ($entries as $entry){
- // Check to see if the User has paid or not
- // Created on
- $time = strtotime($entry['date_created']);
- // Time on Day Ago
- $sub_time = '-24 hour';
- $add_time = '+24 hour';
- $one_day_ago = strtotime($sub_time);
- if(
- $entry['payment_status'] == 'Processing' &&
- $time >= $one_day_ago
- ){
- // This is here because I am showing the exact time of creation, is there a workaround?
- if ( function_exists( 'date_default_timezone_set' ) )
- date_default_timezone_set('America/Chicago'); //this overwrite all settings!!
- // It's sooner than 24 hours, so let's show a counter and expiration date
- $time_left = $time - $one_day_ago;
- $days_left = floor($time_left / 86400); // 86400 = seconds per day
- $hours_left = floor(($time_left - $days_left * 86400) / 3600); // 3600 = seconds per hour
- $mins_left = floor(($time_left - $days_left - $hours_left * 3600) / 60); // 60 = seconds per min
- echo '<b>'.$entry["6.3"].' '.$entry["6.6"].'</b>';
- echo '<br/>Created on: '.date_i18n('M d, Y h:i a', $time);
- $total_time = strtotime($add_time, $time);
- echo "<br/>$hours_left hours & $mins_left min remaining";
- echo '<br/><i>This entry will be deleted on '.date_i18n('M d, Y h:i a', $total_time).'</i><br/><br/>';
- // This is here because I am showing the exact time of creation, is there a workaround?
- // This resets the timezone, without this it messes up the counters...
- if ( function_exists( 'date_default_timezone_set' ) )
- date_default_timezone_set('UTC'); //this overwrite all settings!!
- } else {
- echo '<p><b>'.$entry["6.3"].' '.$entry["6.6"].'</b> hase been deleted.</p>';
- // Get our Leads
- $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 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 );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement