gform_after_delete_form

Description

Use this action hook to perform actions right after a form is deleted.

Usage

add_action( 'gform_after_delete_form', 'do_cleanup' );

function do_cleanup( $form_id ) {
    // Perform your cleanup actions here
    // $form_id is the ID of the form that has been deleted
}

Parameters

ParameterTypeDescription
$form_idintegerID of current form.

Examples

Adds a log file entry when a form is deleted

add_action( 'gform_after_delete_form', 'log_form_deleted' );

function log_form_deleted( $form_id ) {
    $log_file = ABSPATH . '/gf_deleted_forms.log';
    $f = fopen( $log_file, 'a' );
    $user = wp_get_current_user();
    fwrite( $f, date( 'c' ) . " - Form deleted by {$user->user_login}. Form ID: {$form_id}.\n" );
    fclose( $f );
}

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This action hook is located in GFFormsModel::delete_form() in form_model.php.