Okay, I looked around a little more and came up with this. It is probably doing too much work this way, so it can probably be streamlined. This loops through my entries, and finds people with the Payment Status of "Processing" and then completely deletes them.
function my_remove_entries( $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
if($entry['payment_status'] == 'Processing'){
// 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 );
}
}
// Message. Take this out later.
echo 'deleted users!';
}
I have the function being fired on page load in my header.php file. The only piece missing is whether the entry is 24 hours old or not. That's where I am stuck....
Posted 12 years ago on Monday October 1, 2012 |
Permalink