Last active
February 23, 2017 15:40
-
-
Save spivurno/66b3a19bf3288d267399 to your computer and use it in GitHub Desktop.
GP Disable Entry Creation // Gravity Forms // Remove Image URLs from Entry Before Delete
This file contains hidden or 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
| <?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 ); |
This file contains hidden or 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
| <?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