The gform_purge_expired_incomplete_submissions_query filter allows you to override the default query used to purge expired incomplete (save and continue) submissions in Gravity Forms.
Usage
add_filter('gform_purge_expired_incomplete_submissions_query', 'your_function_name', 10);
Parameters
$query (array)
: The delete, from, and where arguments to be used when the query is performed.
More information
See Gravity Forms Docs: gform_purge_expired_incomplete_submissions_query
Place this code in the functions.php
file of your active theme. This filter was added in v2.1.1.20.
Examples
Custom Purge Query
This example modifies the purge query to only delete incomplete submissions from form ID 5.
function custom_purge_query($query) { global $wpdb; $expiration_date = gmdate('Y-m-d H:i:s', time() - ( 7 * 24 * 60 * 60 )); $query['where'] = $wpdb->prepare('WHERE form_id = %d AND date_created < %s', 5, $expiration_date); return $query; } add_filter('gform_purge_expired_incomplete_submissions_query', 'custom_purge_query', 10);
Change Expiration Time
This example changes the expiration time to 14 days instead of the default 7 days.
function change_expiration_time($query) { global $wpdb; $expiration_date = gmdate('Y-m-d H:i:s', time() - ( 14 * 24 * 60 * 60 )); $query['where'] = $wpdb->prepare('WHERE date_created < %s', $expiration_date); return $query; } add_filter('gform_purge_expired_incomplete_submissions_query', 'change_expiration_time', 10);
Exclude Certain Form IDs
This example prevents purging of incomplete submissions for forms with IDs 3 and 4.
function exclude_forms_from_purge($query) { global $wpdb; $expiration_date = gmdate('Y-m-d H:i:s', time() - ( 7 * 24 * 60 * 60 )); $query['where'] = $wpdb->prepare('WHERE form_id NOT IN (%d, %d) AND date_created < %s', 3, 4, $expiration_date); return $query; } add_filter('gform_purge_expired_incomplete_submissions_query', 'exclude_forms_from_purge', 10);
Purge Submissions Older Than 30 Days
This example purges incomplete submissions older than 30 days.
function purge_submissions_older_than_30_days($query) { global $wpdb; $expiration_date = gmdate('Y-m-d H:i:s', time() - ( 30 * 24 * 60 * 60 )); $query['where'] = $wpdb->prepare('WHERE date_created < %s', $expiration_date); return $query; } add_filter('gform_purge_expired_incomplete_submissions_query', 'purge_submissions_older_than_30_days', 10);