gform_dropbox_store_local_version

Description

This filter can be used to keep a local copy of the file being retained once it has been uploaded to Dropbox.

Usage

The following would apply to all forms:

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

To target a specific form append the form id to the hook name. (format: gform_dropbox_store_local_version_FORMID)

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

To target a specific field append both the form id and the field id to the hook name. (format: gform_dropbox_store_local_version_FORMID_FIELDID)

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

Parameters

ParameterTypeDescription
$store_local_versionbooleanShould a local copy of the file be retained? Default is false.
$filearrayThe file properties.
$field_idstringThe ID of the field currently being processed.
$formForm ObjectThe form currently being processed.
$entryEntry ObjectThe entry currently being processed.
$feedFeed ObjectThe feed currently being processed.

Example of the $file array:

array(
	'name'        => basename( $entry[ rgar( $field, 'id' ) ] ),
	'path'        => str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $entry[ rgar( $field, 'id' ) ] ),
	'url'         => $entry[ $field['id'] ],
	'destination' => rgars( $feed, 'meta/destinationFolder' ),
);

Examples

Use the filter with its default behavior.

This example shows the simplest way to use the hook.

add_filter( 'gform_dropbox_store_local_version', '__return_true' );

Retain a local copy based on feed and entry values.

This example shows how you can determine if a local copy should be retained based on the name of the feed and a field value in the Entry Object.

add_filter( 'gform_dropbox_store_local_version_10', 'maybe_store_local_version', 10, 6 );
function maybe_store_local_version( $store_local_version, $file, $field_id, $form, $entry, $feed ) {
	if ( rgars( $feed, 'meta/feedName' ) == 'Dropbox Feed 2' && rgar( $entry, '5' ) == 'No' ) {
		return true;
	}

	return $store_local_version;
}

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?

Source Code

This filter is located in GFDropbox::upload_file() in class-gf-dropbox.php.