Using Gravity Forms ‘gform_pre_note_deleted’ PHP action

The gform_pre_note_deleted Gravity Forms action is triggered before a note is deleted, allowing you to perform additional actions.

Usage

add_action('gform_pre_note_deleted', 'your_custom_function', 10, 2);

Parameters

  • $note_id (int) – The ID of the note being deleted.
  • $entry_id (int) – The ID of the entry that the note is being deleted from.

More information

See Gravity Forms Docs: gform_pre_note_deleted

This action hook is located in forms_model.php.

Examples

Log note deletion

Log note deletion before it’s deleted.

function log_note_deletion($note_id, $entry_id) {
    // Log the note deletion
    error_log("Note ID: {$note_id} will be deleted from Entry ID: {$entry_id}");
}
add_action('gform_pre_note_deleted', 'log_note_deletion', 10, 2);

Prevent note deletion for specific entry

Prevent note deletion for a specific entry by ID.

function prevent_note_deletion($note_id, $entry_id) {
    if ($entry_id == 123) {
        // Do not delete the note
        remove_action('gform_pre_note_deleted', 'prevent_note_deletion', 10, 2);
    }
}
add_action('gform_pre_note_deleted', 'prevent_note_deletion', 10, 2);

Update a custom post when a note is deleted

Update a custom post when a note is deleted from an entry.

function update_custom_post_on_note_deletion($note_id, $entry_id) {
    // Update custom post
    wp_update_post(array(
        'ID' => $entry_id,
        'post_content' => 'Note ' . $note_id . ' has been deleted.'
    ));
}
add_action('gform_pre_note_deleted', 'update_custom_post_on_note_deletion', 10, 2);

Send an email when a note is deleted

Send an email to the site administrator when a note is deleted.

function email_on_note_deletion($note_id, $entry_id) {
    // Send an email to the admin
    wp_mail(get_option('admin_email'), 'Note Deleted', 'A note with ID ' . $note_id . ' was deleted from entry ' . $entry_id . '.');
}
add_action('gform_pre_note_deleted', 'email_on_note_deletion', 10, 2);

Add a note to another entry when a note is deleted

Add a note to another entry when a note is deleted.

function copy_note_to_another_entry($note_id, $entry_id) {
    // Get the note
    $note = GFFormsModel::get_note($note_id);

    // Add the note to another entry
    GFFormsModel::add_note(456, $note->form_id, $note->user_id, $note->field_id, $note->value, 'Note copied from entry ' . $entry_id . '.');
}
add_action('gform_pre_note_deleted', 'copy_note_to_another_entry', 10, 2);