Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasstark/4c75d9e9f0b9f90a3ebea5636825cc82 to your computer and use it in GitHub Desktop.
Save lucasstark/4c75d9e9f0b9f90a3ebea5636825cc82 to your computer and use it in GitHub Desktop.
Enable Gravity Forms Signature for WooCommerce Gravity Forms Product Addons
add_filter( 'gform_delete_lead', function ( $lead_id ) {
if ( function_exists( 'gf_signature' ) ) {
$lead = RGFormsModel::get_lead( $lead_id );
$form = RGFormsModel::get_form_meta( $lead['form_id'] );
if ( ! is_array( $form['fields'] ) ) {
return;
}
foreach ( $form['fields'] as $field ) {
if ( $field->type == 'signature' ) {
$previous_value = gform_get_meta($lead_id, $field->id . '_saved_file');
$filename = 'saved-' . $lead_id . '-' . $field->id . '.png';
$folder = GFSignature::get_signatures_folder();
$file_path = $folder . $filename;
//Prevent files from being deleted from folders other than the signature upload folder
$is_valid_dir = trailingslashit( dirname( $file_path ) ) == $folder;
if ( file_exists( $file_path ) && $is_valid_dir ) {
rename( $file_path, $folder . $previous_value );
}
}
}
}
}, 9999 );
add_filter( 'gform_delete_lead', function ( $lead_id ) {
if ( function_exists( 'gf_signature' ) ) {
$lead = RGFormsModel::get_lead( $lead_id );
$form = RGFormsModel::get_form_meta( $lead['form_id'] );
if ( ! is_array( $form['fields'] ) ) {
return;
}
foreach ( $form['fields'] as $field ) {
if ( $field->type == 'signature' ) {
$filename = rgar( $lead, $field->id );
$folder = GFSignature::get_signatures_folder();
$file_path = $folder . $filename;
//Prevent files from being deleted from folders other than the signature upload folder
$is_valid_dir = trailingslashit( dirname( $file_path ) ) == $folder;
if ( file_exists( $file_path ) && $is_valid_dir ) {
gform_update_meta( $lead_id, $field->id . '_saved_file', $filename );
rename( $file_path, $folder . 'saved-' . $lead_id . '-' . $field->id . '.png' );
}
}
}
}
}, 0 );
@mkhandouzy
Copy link

Does it go to theme's functions.php?

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