Using Gravity Forms ‘gform_pre_delete_feed’ PHP action

The gform_pre_delete_feed action hook allows you to perform a custom action just before a feed is deleted from the database.

Usage

To run the hook for all add-ons:

add_action('gform_pre_delete_feed', 'your_function_name', 10, 2);

To target a specific add-on:

add_action('gform_{SHORT_SLUG}_pre_delete_feed', 'your_function_name', 10, 2);

Refer to the Gravity Forms Add-On Slugs article for a list of possible short slugs.

Parameters

  • $id (int) – The ID of the feed being deleted.
  • $addon (object) – The current instance of the add-on object which extends GFFeedAddOn or GFPaymentAddOn (e.g. GFCoupons, GF_User_Registration, GFStripe).

More information

See Gravity Forms Docs: gform_pre_delete_feed

This action hook was introduced in Gravity Forms 2.4.20.4 and is located in GFFeedAddOn::delete_feed() in /includes/addons/class-gf-feed-addon.php.

Examples

Log feed before it is deleted

Retrieve the feed before deletion and log it:

add_action('gform_pre_delete_feed', 'log_pre_delete_feed', 10, 2);

function log_pre_delete_feed($id, $addon) {
    $feed = $addon->get_feed($id);
    error_log("Feed with ID {$id} is going to be deleted: " . print_r($feed, true));
}

Log deletion of User Registration add-on feeds

Log the deletion of User Registration add-on feeds:

add_action('gform_user_registration_pre_delete_feed', 'log_user_registration_feed_deletion', 10, 2);

function log_user_registration_feed_deletion($id, $addon) {
    error_log("User Registration feed with ID {$id} was deleted.");
}

Send notification before feed deletion

Send a notification email before a feed is deleted:

add_action('gform_pre_delete_feed', 'send_feed_deletion_notification', 10, 2);

function send_feed_deletion_notification($id, $addon) {
    $to = '[email protected]';
    $subject = "Feed {$id} is going to be deleted";
    $message = "A feed with ID {$id} is about to be deleted.";
    wp_mail($to, $subject, $message);
}

Modify feed data before deletion

Perform modifications to the feed data before deletion:

add_action('gform_pre_delete_feed', 'modify_feed_data_before_deletion', 10, 2);

function modify_feed_data_before_deletion($id, $addon) {
    $feed = $addon->get_feed($id);
    // Modify the $feed data, for example, set all form IDs to 0
    $feed['meta']['form_id'] = 0;
    $addon->update_feed_meta($id, $feed['meta']);
}

Remove related data from the database before the feed is deleted:

add_action('gform_pre_delete_feed', 'remove_related_data_before_deletion', 10, 2);

function remove_related_data_before_deletion($id, $addon) {
    global $wpdb;
    $table_name = $wpdb->prefix . 'your_custom_table';
    $wpdb->delete($table_name, array('feed_id' => $id), array('%d'));
}