Last active
February 27, 2026 21:01
-
-
Save zackkatz/5d6d4e1c129992e816d802bf1b1d3ff6 to your computer and use it in GitHub Desktop.
GravityKit - Disable Entry Creation: Automatically delete a Gravity Forms entry and any associated files after submission. Enable per-form in Form Settings > Restrictions.
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 | |
| /** | |
| * Plugin Name: GravityKit - Disable Entry Creation | |
| * Plugin URI: https://www.gravitykit.com | |
| * Description: Automatically delete a Gravity Forms entry and any associated files after the form is submitted. Enable per-form in Form Settings. | |
| * Version: 1.0 | |
| * Author: GravityKit | |
| * Author URI: https://www.gravitykit.com | |
| * License: GPL-2.0+ | |
| * Requires Plugins: gravityforms | |
| * | |
| * For more functionality, see {@link https://gravitywiz.com/documentation/gravity-forms-disable-entry-creation/} | |
| */ | |
| defined( 'ABSPATH' ) || exit; | |
| add_filter( 'gform_form_settings_fields', 'gk_disable_entry_creation_add_form_setting', 10, 2 ); | |
| add_action( 'gform_after_submission', 'gk_disable_entry_creation_after_submission', 999, 2 ); | |
| /** | |
| * Adds the "Disable Entry Creation" toggle to Form Settings > Restrictions. | |
| * | |
| * @param array $fields Form settings fields. | |
| * @param array $form Current form. | |
| * | |
| * @return array | |
| */ | |
| function gk_disable_entry_creation_add_form_setting( $fields, $form ) { | |
| $fields['restrictions']['fields'][] = array( | |
| 'name' => 'gk_disable_entry_creation', | |
| 'type' => 'toggle', | |
| 'label' => esc_html__( 'Disable Entry Creation', 'gk-disable-entry-creation' ), | |
| 'tooltip' => esc_html__( 'When enabled, the entry and any uploaded files will be deleted after the form submission has been fully processed (notifications sent, feeds executed, etc.).', 'gk-disable-entry-creation' ), | |
| 'default_value' => false, | |
| ); | |
| return $fields; | |
| } | |
| /** | |
| * Deletes the entry after submission if the form setting is enabled. | |
| * | |
| * Hooked at priority 999 so all other gform_after_submission handlers | |
| * (notifications, add-on feeds, etc.) run first. | |
| * | |
| * @param array $entry The Entry object. | |
| * @param array $form The Form object. | |
| */ | |
| function gk_disable_entry_creation_after_submission( $entry, $form ) { | |
| if ( empty( $form['gk_disable_entry_creation'] ) || '1' !== (string) $form['gk_disable_entry_creation'] ) { | |
| return; | |
| } | |
| /** | |
| * Filters whether the entry should be deleted. | |
| * | |
| * @param bool $should_delete Whether to delete the entry. Default true. | |
| * @param array $entry The Entry object. | |
| * @param array $form The Form object. | |
| */ | |
| if ( ! apply_filters( 'gk/snippet/disable-entry-creation/should-delete', true, $entry, $form ) ) { | |
| return; | |
| } | |
| $entry_id = rgar( $entry, 'id' ); | |
| if ( ! $entry_id ) { | |
| return; | |
| } | |
| // GFAPI::delete_entry() handles file deletion via GFFormsModel::delete_files(). | |
| $result = GFAPI::delete_entry( $entry_id ); | |
| if ( is_wp_error( $result ) ) { | |
| GFCommon::log_error( __FUNCTION__ . "(): Failed to delete entry #{$entry_id}: " . $result->get_error_message() ); | |
| } else { | |
| GFCommon::log_debug( __FUNCTION__ . "(): Deleted entry #{$entry_id} for form #{$form['id']} (Disable Entry Creation)." ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment