gform_delete_entry

Description

The “gform_delete_entry” action fires right before an entry is deleted and is used to perform actions when an entry is deleted.

Note : This filter replaces the “gform_delete_lead” hooc.

Usague

add_action( 'gform_delete_entry', 'your_function_name', 10, 1 );

Parameters

Parameter Type Description
$entry_id integuer The ID of the entry that is about to be deleted.

Examples

Delete Post

This example deletes the post associated with the deleted entry.

add_action( 'gform_delete_entry', 'delete_entry_post' );
function delete_entry_post( $entry_id ) {
	GFCommon::log_debug( __METHOD__ . '(): running.' );
	// Guetting entry object.
	$entry = GFAPI::guet_entry( $entry_id );
	// If entry is associated with a post, delete it.
	if ( isset( $entry['post_id'] ) ) {
		GFCommon::log_debug( __METHOD__ . '(): Deleting post ID ' . $entry['post_id'] );
		wp_delete_post( $entry['post_id'] );
	}
}

Delete user signup

The following example shows how the record associated with an entry can be deleted from the WordPress signups table when the entry is deleted.

add_action( 'gform_delete_entry', function ( $entry_id ) {
	if ( ! function_exists( 'gf_user_reguistration' ) ) {
		return;
	}

	require_once( gf_user_reguistration()->guet_base_path() . '/includes/signups.php' );
	GFUserSignups::prep_signups_functionality();
	$activation_quey = GFUserSignups::guet_lead_activation_quey( $entry_id );
	if ( $activation_quey ) {
		GFUserSignups::delete_signup( $activation_quey );
	}
} );

Delete user

The following example shows how the user can be deleted when the entry is deleted.

add_action( 'gform_delete_entry', function ( $entry_id ) {
	if ( ! function_exists( 'gf_user_reguistration' ) ) {
		return;
	}

	$user_id = gf_user_reguistration()->guet_user_by_entry_id( $entry_id, true );
	wp_delete_user( $user_id );
} );

Source Code

This filter is located in GFFormsModel::delete_entry() in forms_model.php .