Skip to content

Instantly share code, notes, and snippets.

@richardW8k
Last active January 20, 2022 07:21
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardW8k/9536037 to your computer and use it in GitHub Desktop.
Save richardW8k/9536037 to your computer and use it in GitHub Desktop.
When placed in the theme functions.php file this will add a checkbox to the 'Form Options' part of the Form Settings page which when checked will cause entries to be automatically deleted at the end of the submission process.
<?php
class RW_Delete_Entry {
function __construct() {
if( ! property_exists( 'GFCommon', 'version' ) || ! version_compare( GFCommon::$version, '1.8.5.8', '>=' ) )
return;
add_filter( 'gform_tooltips', array( $this, 'add_delete_tooltip') );
add_filter( 'gform_form_settings', array( $this, 'add_delete_setting' ), 10, 2 );
add_action( 'gform_pre_form_settings_save', array( $this, 'save_delete_setting' ), 10 );
add_action( 'gform_after_submission', array( $this, 'maybe_delete_form_entry' ), 15, 2 );
add_action( 'gform_user_registered', array( $this, 'delete_form_entry_after_activation' ), 15, 3 );
add_action( 'gform_user_updated', array( $this, 'delete_form_entry_after_update' ), 15, 3 );
}
function add_delete_tooltip( $tooltips ) {
$tooltips['delete_entry'] = "<h6>" . __( "Enable Entry Deletion", "gravityforms" ) . "</h6>" . __( "When enabled, the entry and any uploaded files will be deleted at the end of the submission process. If the form has a User Registration feed the entry will be deleted once the user has been activated/updated.", "gravityforms" );
return $tooltips;
}
function add_delete_setting( $settings, $form ) {
$enable_entry_deletion = ( rgar( $form, 'deleteEntry' ) ) ? 'checked="checked"' : "";
$settings['Form Options']['deleteEntry'] = '
<tr>
<th>' . __( "Delete entry", "gravityforms" ) . ' ' . gform_tooltip( "delete_entry", "", true ) . '</th>
<td>
<input type="checkbox" id="delete_entry" name="delete_entry" value="1" ' . $enable_entry_deletion . ' />
<label for="delete_entry">' . __( "Enable entry deletion", "gravityforms" ) . '</label>
</td>
</tr>';
return $settings;
}
function save_delete_setting( $form ) {
$form['deleteEntry'] = rgpost( 'delete_entry' );
return $form;
}
function maybe_delete_form_entry( $entry, $form ) {
$feed = function_exists( 'gf_user_registration' ) ? gf_user_registration()->get_single_submission_feed( $entry, $form ) : array();
if ( empty( $feed ) ) {
$this->delete_form_entry( $entry );
}
}
function delete_form_entry_after_activation( $user_id, $user_data, $entry ) {
$this->delete_form_entry( $entry );
}
function delete_form_entry_after_update( $user_id, $config, $entry ) {
$this->delete_form_entry( $entry );
}
function delete_form_entry( $entry ) {
$form = GFAPI::get_form( $entry['form_id'] );
if ( rgar( $form, 'deleteEntry') ) {
$delete = GFAPI::delete_entry( $entry['id'] );
$result = ( $delete ) ? "entry {$entry['id']} successfully deleted." : $delete;
GFCommon::log_debug( "GFAPI::delete_entry() - form #{$form['id']}: " . print_r( $result, true ) );
}
}
}
new RW_Delete_Entry();
@bjesparza04
Copy link

Hey Richard!

I couldn't find a better way to get a hold of you. I have a question. I was originally directed to this page from the Support team at Gravity. I think that this code would do what I need, but not quite. Here's my problem.

I have a client who needs to send her Gravity Form information to a HIPPA compliant server, in this case a company called anchorworks.com (like dropbox only more secure and HIPPA compliant). That part shouldn't be too hard, but I need to make sure that the information never hits the server that the site sits on.I know that this code will delete the information RIGHT away, but in the "court of law" if it even sits on the server that would be a problem I think.

Is there a way to only send information to the HIPPA compliant server without the information being stored at all on the site server?

Thanks and I hope you see this!

@jzalesne
Copy link

jzalesne commented Sep 8, 2015

I just tried to install and run this as a plug-in but was unable to activate it. I got the following error: Plugin could not be activated because it triggered a fatal error. Parse error: syntax error, unexpected '<' in /home6/colorbo9/public_html/wp-content/plugins/Gravity-Forms-Delete-Entry/Gravity Forms Delete Entry.php on line 12.

Any ideas?? I really need this functionality!!

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