The gform_file_upload_whitelisting_disabled Gravity Forms PHP filter allows you to disable file upload whitelisting. This filter applies to all forms.
Usage
Use the filter to disable file upload whitelisting for all forms:
add_filter('gform_file_upload_whitelisting_disabled', '__return_true');
Parameters
- $disabled (bool): Set to
true
to disable whitelisting. Defaults tofalse
.
More information
See Gravity Forms Docs: gform_file_upload_whitelisting_disabled
This code should be placed in the functions.php file of your active theme.
Examples
Disabling file upload whitelisting for all forms
Disable file upload whitelisting for all forms to allow any file type to be uploaded:
add_filter('gform_file_upload_whitelisting_disabled', '__return_true');
Enabling file upload whitelisting for all forms
Enable file upload whitelisting for all forms so only specific file types can be uploaded:
add_filter('gform_file_upload_whitelisting_disabled', '__return_false');
Conditionally disable file upload whitelisting
Disable file upload whitelisting for specific forms based on form ID:
function disable_whitelisting_for_specific_form($disabled, $form_id) { // Disable whitelisting for form ID 5 if ($form_id == 5) { return true; } return $disabled; } add_filter('gform_file_upload_whitelisting_disabled', 'disable_whitelisting_for_specific_form', 10, 2);
Enable whitelisting for specific file types
Allow only specific file types for all forms:
function enable_specific_file_types($mimes) { // Allow only PDF and JPEG files return array( 'pdf' => 'application/pdf', 'jpg|jpeg' => 'image/jpeg', ); } add_filter('gform_allowed_upload_mimes', 'enable_specific_file_types');
Disable file upload whitelisting based on user role
Disable file upload whitelisting for users with the ‘editor’ role:
function disable_whitelisting_for_editors($disabled) { if (current_user_can('editor')) { return true; } return $disabled; } add_filter('gform_file_upload_whitelisting_disabled', 'disable_whitelisting_for_editors');