Using Gravity Forms ‘gform_pre_notification_deleted’ PHP action

The gform_pre_notification_deleted action event is triggered before a notification is deleted in Gravity Forms.

Usage

To use this action, add the following code to your theme’s functions.php file or a custom plugin:

add_action('gform_pre_notification_deleted', 'my_custom_function', 10, 2);

function my_custom_function($notification_id, $form) {
    // your custom code here
}

Parameters

  • $notification_id (int) – The ID of the notification being deleted.
  • $form (array) – The form object associated with the notification.

More information

See Gravity Forms Docs: gform_pre_notification_deleted

This action is implemented in Gravity Forms version 1.0 and is not deprecated. The source code for this action is located in notification.php.

Examples

Log notification deletion

Log the notification ID and form ID before a notification is deleted:

function log_notification_deletion($notification_id, $form) {
    error_log("Notification ID: $notification_id will be deleted from Form ID: {$form['id']}");
}
add_action('gform_pre_notification_deleted', 'log_notification_deletion', 10, 2);

Prevent notification deletion for a specific form

Prevent notifications from being deleted on a specific form (e.g., form ID 5):

function prevent_notification_deletion($notification_id, $form) {
    if ($form['id'] == 5) {
        wp_die('Notifications cannot be deleted for this form.');
    }
}
add_action('gform_pre_notification_deleted', 'prevent_notification_deletion', 10, 2);

Send a custom email when a notification is deleted

Send an email to the admin when a notification is deleted:

function email_admin_on_notification_deletion($notification_id, $form) {
    $admin_email = get_option('admin_email');
    $subject = "Notification Deleted";
    $message = "A notification with ID: $notification_id was deleted from form ID: {$form['id']}.";
    wp_mail($admin_email, $subject, $message);
}
add_action('gform_pre_notification_deleted', 'email_admin_on_notification_deletion', 10, 2);

Backup deleted notifications

Backup notification settings to a file before deletion:

function backup_deleted_notification($notification_id, $form) {
    $file = fopen("backup_notifications.txt", "a+");
    $current_notification = json_encode(array('notification_id' => $notification_id, 'form' => $form));
    fwrite($file, $current_notification . PHP_EOL);
    fclose($file);
}
add_action('gform_pre_notification_deleted', 'backup_deleted_notification', 10, 2);

Remove related data in a custom table when a notification is deleted:

function delete_related_data_on_notification_deletion($notification_id, $form) {
    global $wpdb;
    $table_name = $wpdb->prefix . "my_custom_table";
    $wpdb->delete($table_name, array('notification_id' => $notification_id), array('%d'));
}
add_action('gform_pre_notification_deleted', 'delete_related_data_on_notification_deletion', 10, 2);