The gform_cleanup_target_dir Gravity Forms PHP filter is used to bypass functionality that relies on open_dir()
, enabling support for the multi-file upload field on servers that don’t support open_dir()
, such as WordPress VIP.
Usage
To use the filter for all multi-file enabled file uploads:
add_filter('gform_cleanup_target_dir', 'your_function_name');
Parameters
- $cleanup_target_dir (boolean): Indicates if old temporary files should be removed from the forms tmp directory. Default:
true
.
More information
See Gravity Forms Docs: gform_cleanup_target_dir
Examples
Disable cleanup of temporary files
Disable the removal of old temporary files from the forms tmp directory.
function disable_cleanup_target_dir() { return false; } add_filter('gform_cleanup_target_dir', 'disable_cleanup_target_dir');
Enable cleanup of temporary files
Force the removal of old temporary files from the forms tmp directory.
function enable_cleanup_target_dir() { return true; } add_filter('gform_cleanup_target_dir', 'enable_cleanup_target_dir');
Cleanup target directory conditionally
Only remove old temporary files from the forms tmp directory if the current user is an admin.
function conditional_cleanup_target_dir() { return current_user_can('manage_options'); } add_filter('gform_cleanup_target_dir', 'conditional_cleanup_target_dir');
Cleanup target directory on specific days
Only remove old temporary files from the forms tmp directory on Mondays.
function cleanup_target_dir_on_mondays() { return (date('w') == 1); } add_filter('gform_cleanup_target_dir', 'cleanup_target_dir_on_mondays');
Custom cleanup behavior
Create a custom cleanup behavior for the forms tmp directory using your own logic.
function custom_cleanup_behavior() { // Your custom code here return true; // Or false, depending on your logic } add_filter('gform_cleanup_target_dir', 'custom_cleanup_behavior');