The gform_after_delete_form is a Gravity Forms filter that allows you to perform actions right after a form is deleted in your WordPress site.
Usage
add_action( 'gform_after_delete_form', 'my_custom_function' ); function my_custom_function( $form_id ) { // your custom code here return $form_id; }
Parameters
- $form_id (integer): The ID of the form that has been deleted.
More Information
See Gravity Forms Docs: gform_after_delete_form
This filter hook is available since Gravity Forms version 2.5 and is not deprecated. The source code is located in GFFormsModel::delete_form()
in form_model.php
.
Examples
Logging Form Deletion
This example records the deletion of a form in a log file. It captures the time of deletion, the username of the user who deleted the form, and the ID of the deleted form.
add_action( 'gform_after_delete_form', 'log_form_deletion' ); function log_form_deletion( $form_id ) { // Path to the log file $log_file_path = ABSPATH . '/gf_deleted_forms.log'; // Open the file in append mode $file = fopen( $log_file_path, 'a' ); // Get the current user $user = wp_get_current_user(); // Write the log entry fwrite( $file, date( 'c' ) . " - Form deleted by {$user->user_login}. Form ID: {$form_id}.\n" ); // Close the file fclose( $file ); }
The ABSPATH
variable contains the absolute path to the WordPress directory. The wp_get_current_user()
function retrieves the current user’s data. The fwrite()
function writes the log entry to the file. Finally, the fclose()
function closes the file to free up system resources.