The gform_temp_file_expiration_days filter allows you to change the number of days before temporary file uploads are deleted.
Usage
add_filter('gform_temp_file_expiration_days', 'your_function_name');
Parameters
- $expiration_days (int) – The number of days temporary files should remain in the uploads directory. Default is 2 or 30 if save and continue is enabled.
- $form (Form Object) – The form currently being processed.
More information
See Gravity Forms Docs: gform_temp_file_expiration_days
This filter was introduced in Gravity Forms 2.1.3.5.
The source code for this filter is located in GFFormDisplay::clean_up_files() in form_display.php.
Examples
Set temporary file expiration to 90 days
This example changes the temporary file expiration period to 90 days.
add_filter('gform_temp_file_expiration_days', 'temp_file_expiration_days'); function temp_file_expiration_days($expiration_days) { $expiration_days = 90; return $expiration_days; }
Set temporary file expiration based on form ID
This example sets the temporary file expiration period to 7 days for form with ID 5 and 14 days for form with ID 7.
add_filter('gform_temp_file_expiration_days', 'temp_file_expiration_by_form_id', 10, 2); function temp_file_expiration_by_form_id($expiration_days, $form) { if ($form['id'] == 5) { $expiration_days = 7; } elseif ($form['id'] == 7) { $expiration_days = 14; } return $expiration_days; }
Disable temporary file deletion
This example disables the automatic deletion of temporary files by setting the expiration period to a very large number.
add_filter('gform_temp_file_expiration_days', 'disable_temp_file_deletion'); function disable_temp_file_deletion($expiration_days) { $expiration_days = 999999; return $expiration_days; }
Set temporary file expiration for specific form type
This example sets the temporary file expiration period to 45 days for forms with the title “Special Form”.
add_filter('gform_temp_file_expiration_days', 'temp_file_expiration_for_special_form', 10, 2); function temp_file_expiration_for_special_form($expiration_days, $form) { if ($form['title'] == 'Special Form') { $expiration_days = 45; } return $expiration_days; }
Set temporary file expiration based on user role
This example sets the temporary file expiration period to 60 days for users with the “editor” role.
add_filter('gform_temp_file_expiration_days', 'temp_file_expiration_for_editors', 10, 2); function temp_file_expiration_for_editors($expiration_days, $form) { $user = wp_get_current_user(); if (in_array('editor', (array) $user->roles)) { $expiration_days = 60; } return $expiration_days; }