The gform_delete_entry action in Gravity Forms is triggered right before an entry is deleted, allowing you to perform additional actions when an entry is deleted.
Usage
add_action('gform_delete_entry', 'your_function_name', 10, 1);
Parameters
- $entry_id (integer) – The ID of the entry that is about to be deleted.
More information
See Gravity Forms Docs: gform_delete_entry
Note: This action replaces the “gform_delete_lead” hook.
Examples
Delete Post
This example deletes the post associated with the deleted entry.
add_action('gform_delete_entry', 'delete_entry_post'); function delete_entry_post($entry_id) { GFCommon::log_debug(__METHOD__ . '(): running.'); // Getting entry object $entry = GFAPI::get_entry($entry_id); // If entry is associated with a post, delete it. if (isset($entry['post_id'])) { GFCommon::log_debug(__METHOD__ . '(): Deleting post ID ' . $entry['post_id']); wp_delete_post($entry['post_id']); } }
Delete user signup
This example shows how to delete the record associated with an entry from the WordPress signups table when the entry is deleted.
add_action('gform_delete_entry', function($entry_id) { if (!function_exists('gf_user_registration')) { return; } require_once(gf_user_registration()->get_base_path() . '/includes/signups.php'); GFUserSignups::prep_signups_functionality(); $activation_key = GFUserSignups::get_lead_activation_key($entry_id); if ($activation_key) { GFUserSignups::delete_signup($activation_key); } });
Delete user
This example shows how to delete the user when the entry is deleted.
add_action('gform_delete_entry', function($entry_id) { if (!function_exists('gf_user_registration')) { return; } $user_id = gf_user_registration()->get_user_by_entry_id($entry_id, true); wp_delete_user($user_id); });
Source Code
This action is located in GFFormsModel::delete_entry() in forms_model.php.