The gform_secure_file_download_is_https filter allows you to override SSL replacement in Gravity Forms. By default, Gravity Forms tries to determine if the URL schema should be overwritten for SSL, which is not ideal for all situations, especially domain mapping. Setting $field_ssl
to false
will prevent the override.
Usage
Here’s a generic example of how to use the filter:
add_filter('gform_secure_file_download_is_https', 'your_function_name', 10, 3); function your_function_name($field_ssl, $file_url, $field) { // your custom code here return $field_ssl; }
Parameters
$field_ssl
(bool): Set totrue
to allow override if needed, orfalse
to disable override. Defaults totrue
.$file_url
(string): The file URL in question.$field
(GF_Field_Fileupload): The field object for further context.
More information
See Gravity Forms Docs: gform_secure_file_download_is_https
Place this code in the functions.php
file of your active theme.
Examples
Disabling SSL override for a specific domain
In this example, we disable the SSL override for a specific domain:
add_filter('gform_secure_file_download_is_https', 'disable_ssl_override_for_domain', 10, 3); function disable_ssl_override_for_domain($field_ssl, $file_url, $field) { if (strpos($file_url, 'example.com') !== false) { return false; } return $field_ssl; }
Always disable SSL override
In this example, we always disable the SSL override:
add_filter('gform_secure_file_download_is_https', 'always_disable_ssl_override', 10, 3); function always_disable_ssl_override($field_ssl, $file_url, $field) { return false; }
Enable SSL override only for images
In this example, we enable the SSL override only for image file uploads:
add_filter('gform_secure_file_download_is_https', 'ssl_override_for_images', 10, 3); function ssl_override_for_images($field_ssl, $file_url, $field) { $image_extensions = array('jpg', 'jpeg', 'png', 'gif'); $file_extension = pathinfo($file_url, PATHINFO_EXTENSION); if (in_array($file_extension, $image_extensions)) { return true; } return $field_ssl; }
Disable SSL override for specific form
In this example, we disable the SSL override only for a specific form with form ID 5:
add_filter('gform_secure_file_download_is_https', 'ssl_override_for_form', 10, 3); function ssl_override_for_form($field_ssl, $file_url, $field) { if ($field->formId == 5) { return false; } return $field_ssl; }