Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save phillipwilhelm/83e31ca60d56ca5ee46657a05f7034a4 to your computer and use it in GitHub Desktop.
Save phillipwilhelm/83e31ca60d56ca5ee46657a05f7034a4 to your computer and use it in GitHub Desktop.
GP Disable Entry Creation // Gravity Forms // Remove Image URLs from Entry Before Delete
/**
* GP Disable Entry Creation // Gravity Forms // Prevent Image Deletion (for all forms)
*
* GF will go through an entry when it is deleted and remove all of the files associated with that entry. We can bypass
* this by removing the image URLs from the entry prior to deleting it.
*/
add_action( 'gform_after_submission', function( $entry, $form ) {
$fields = GFCommon::get_fields_by_type( $form, array( 'fileupload', 'post_image' ) );
if( ! is_array( $fields ) ) {
return;
}
foreach ( $fields as $field ) {
$entry[ $field->id ] = '';
$cache_key = 'GFFormsModel::get_lead_field_value_' . $entry['id'] . '_' . $field->id;
GFCache::delete( $cache_key );
}
GFAPI::update_entry( $entry );
}, 9, 2 );
<?php
/**
* GP Disable Entry Creation // Gravity Forms // Prevent Image Deletion
*
* GF will go through an entry when it is deleted and remove all of the files associated with that entry. We can bypass
* this by removing the image URLs from the entry prior to deleting it.
*/
add_action( 'gform_user_updated', function( $user_id, $config, $entry ) {
$form = GFAPI::get_form( $entry['form_id'] );
$fields = GFCommon::get_fields_by_type( $form, array( 'fileupload', 'post_image' ) );
if( ! is_array( $fields ) ) {
return;
}
foreach ( $fields as $field ) {
$entry[ $field->id ] = '';
$cache_key = 'GFFormsModel::get_lead_field_value_' . $entry['id'] . '_' . $field->id;
GFCache::delete( $cache_key );
}
GFAPI::update_entry( $entry );
}, 9, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment