gform_advancedpostcreation_file_url_pre_set_post_thumbnail

Description

The gform_advancedpostcreation_file_url_pre_set_post_thumbnail filter can be used to override the URL of the file to be added to the media library and set as the post thumbnail.

Usage

The filter which runs for all forms with an active Advanced Post Creation feed and a field mapped to the Featured Image setting would be used like so:

add_filter( 'gform_advancedpostcreation_file_url_pre_set_post_thumbnail', 'your_function_name', 10, 6 );

To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_advancedpostcreation_file_url_pre_set_post_thumbnail_FORMID)

add_filter( 'gform_advancedpostcreation_file_url_pre_set_post_thumbnail_3', 'your_function_name', 10, 6 );

To limit the scope of your function to a specific form and field, append both the form and field id’s to the end of the hook name. (format: gform_advancedpostcreation_file_url_pre_set_post_thumbnail_FORMID_FIELDID)

add_filter( 'gform_advancedpostcreation_file_url_pre_set_post_thumbnail_3_4', 'your_function_name', 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.

Examples

Use a file from multi-file field

This example shows how you can 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 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Since

This filter was added in v1.3.

Source Code

This filter is located in GF_Advanced_Post_Creation::maybe_set_post_thumbnail() in class-gf-advancedpostcreation.php.