Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spivurno/35b86c47cdf0124be735 to your computer and use it in GitHub Desktop.
Save spivurno/35b86c47cdf0124be735 to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Field-specific Upload Path (Simple)
<?php
/**
* Gravity Wiz // Gravity Forms // Field-specific Upload Path
*
* Provides a method for specifying field-specific file upload paths.
*
* @version 1.0
* @author David Smith <david@gravitywiz.com>
* @license GPL-2.0+
* @link http://gravitywiz.com/...
*/
class GF_Field_Specific_File_Upload_Path {
var $current_field_id = null;
function __construct() {
add_filter( 'gform_save_field_value', array( $this, 'stash_current_field_id' ), 10, 3 );
add_filter( 'gform_upload_path', array( $this, 'modify_upload_path' ) );
}
function stash_current_field_id( $value, $entry, $field ) {
$this->current_field_id = $field['id'];
}
function modify_upload_path( $upload_path ) {
// modify the upload path based on the current field ID:
// $current_field_id = $this->current_field_id
return $upload_path;
}
}
new GF_Field_Specific_File_Upload_Path();
@InterRegister
Copy link

How do I use this in my gravity form?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment