spivurno
5/8/2015 - 12:24 PM

GP Disable Entry Creation // Gravity Forms // Remove Image URLs from Entry Before Delete

GP Disable Entry Creation // Gravity Forms // Remove Image URLs from Entry Before Delete

<?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 );
<?php
/**
 * 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 );