Created
April 29, 2019 16:33
-
-
Save lucasstark/4c75d9e9f0b9f90a3ebea5636825cc82 to your computer and use it in GitHub Desktop.
Enable Gravity Forms Signature for WooCommerce Gravity Forms Product Addons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does it go to theme's functions.php?