Description
The gform_dropbox_should_upload_file filter can be used to determine if a file for a fileupload or dropbox type field is uploaded to Dropbox.
Usage
The following would apply to all forms:
add_filter( 'gform_dropbox_should_upload_file', 'your_function_name', 10, 7 );
To target a specific form append the form id to the hook name. (format: gform_dropbox_should_upload_file_FORMID)
add_filter( 'gform_dropbox_should_upload_file_2', 'your_function_name', 10, 7 );
To target a specific field append both the form id and the field id to the hook name. (format: gform_dropbox_should_upload_file_FORMID_FIELDID)
add_filter( 'gform_dropbox_should_upload_file_2_3', 'your_function_name', 10, 7 );
Parameters
- $should_upload_file boolean
Indicates if the file should be uploaded to Dropbox. - $url string
The URL of the file from the entry. - $existing false|array
False or an array of files previously uploaded to Dropbox for the current field and entry. - $field Field Object
The current fileupload or dropbox field object - $form Form Object
The form containing the current field. - $entry Entry Object
The entry currently being processed. - $feed Feed Object
The feed currently being processed.
Examples
1. Log the params
This is a basic usage example showing how you can log the parameters available to this filter.
add_filter( 'gform_dropbox_should_upload_file', 'log_gform_dropbox_should_upload_file', 10, 7 );
add_filter( 'gform_dropbox_should_upload_file_18', 'log_gform_dropbox_should_upload_file', 10, 7 );
add_filter( 'gform_dropbox_should_upload_file_18_6', 'log_gform_dropbox_should_upload_file', 10, 7 );
function log_gform_dropbox_should_upload_file( $should_upload_file, $url, $existing, $field, $form, $entry, $feed ) {
gf_dropbox()->log_debug( current_filter() . ': ' . print_r( func_get_args(), true ) );
return $should_upload_file;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom functions plugin, or your custom add-on.
Since
This filter was added in version 3.0.1.
Source Code
public function should_upload_file( $url, $existing, $field, $form, $entry, $feed ) {
if ( ! empty( $existing ) ) {
$should_upload_file = ! in_array( $url, $existing );
} else {
// The preview link type uses www.dropbox.com.
$should_upload_file = $field instanceof GF_Field_Dropbox && $field->get_link_type( $form ) === 'preview' || stripos( $url, 'www.dropbox.com' ) === false;
}
$filter_args = array( 'gform_dropbox_should_upload_file', $form['id'], $field->id );
if ( function_exists( 'gf_has_filters' ) && gf_has_filters( $filter_args ) ) {
$this->log_debug( __METHOD__ . '(): Executing functions hooked to gform_dropbox_should_upload_file.' );
}
/**
* Provides a way to prevent the uploading of a file to Dropbox.
*
* @since 3.1
*
* @param bool $should_upload_file Indicates if the file should be uploaded to Dropbox.
* @param string $url The URL of the file from the entry.
* @param false|array $existing False or an array of files previously uploaded to Dropbox for the current field and entry.
* @param GF_Field $field The current fileupload or dropbox field object.
* @param array $form The current form object.
* @param array $entry The current entry object.
* @param array $feed The current feed object.
*/
return (bool) gf_apply_filters( $filter_args, $should_upload_file, $url, $existing, $field, $form, $entry, $feed );
}
This filter is located in GFDropbox::should_upload_file() in class-gf-dropbox.php.