Description
Use this action hook to perform actions right before a field is deleted from a form.
Usage
add_action( 'gform_before_delete_field', 'do_cleanup', 10, 2 );
Parameters
Examples
This example adds a log file entry when a field is deleted.
add_action( 'gform_before_delete_field', 'log_field_deleted', 10, 2 );
function log_field_deleted( $form_id, $field_id ) {
$log_file = ABSPATH . '/gf_deleted_fields.log';
$f = fopen( $log_file, 'a' );
$user = wp_get_current_user();
$form = GFAPI::get_form( $form_id );
$field = GFFormsModel::get_field( $form, $field_id );
$label = is_object( $field ) ? $field->label : 'Unknown';
fwrite( $f, date( 'c' ) . " - Field deleted by {$user->user_login}. Form ID: {$form_id}. Field: {$label} (ID: {$field_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_field() in form_model.php.