The gform_advancedpostcreation_file_url_pre_set_post_thumbnail filter allows you to override the URL of the file to be added to the media library and set as the post thumbnail.
Usage
A generic example of how to use the filter:
add_filter('gform_advancedpostcreation_file_url_pre_set_post_thumbnail', 'your_custom_function', 10, 6);
To limit the scope of your function to a specific form, append the form ID to the end of the hook name:
add_filter('gform_advancedpostcreation_file_url_pre_set_post_thumbnail_3', 'your_custom_function', 10, 6);
To limit the scope of your function to a specific form and field, append both the form and field IDs to the end of the hook name:
add_filter('gform_advancedpostcreation_file_url_pre_set_post_thumbnail_3_4', 'your_custom_function', 10, 6);
Parameters
$file_url(string) – The URL of the file to be added to the media library and set as the post thumbnail.$field_id(int | string) – The form field ID or entry meta key mapped to the feed postThumbnail setting.$feed(Feed Object) – The feed currently being processed.$entry(Entry Object) – The entry currently being processed.$form(Form Object) – The form currently being processed.$post_id(int) – The ID of the post the thumbnail is to be set for.
More information
See Gravity Forms Docs: gform_advancedpostcreation_file_url_pre_set_post_thumbnail
Examples
Use a file from a multi-file field
This example demonstrates how to use a file from a multi-file enabled upload field.
add_filter('gform_advancedpostcreation_file_url_pre_set_post_thumbnail', function($file_url, $field_id, $feed, $entry, $form, $post_id) {
$file_urls = json_decode(rgar($entry, 3), true);
if (!empty($file_urls)) {
$file_url = $file_urls[0];
}
return $file_url;
}, 10, 6);
Place this code in the functions.php file of the active theme, a custom functions plugin, or a custom add-on. For more information on where to put this code, see the Where Do I Put This Code? article.
This filter was added in v1.3 and its source code is located in GF_Advanced_Post_Creation::maybe_set_post_thumbnail() in class-gf-advancedpostcreation.php.