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” hook.

Usage

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

Parameters

  • $entry_id integer
    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.' );
	// Getting entry object.
	$entry = GFAPI::get_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_registration' ) ) {
		return;
	}

	require_once( gf_user_registration()->get_base_path() . '/includes/signups.php' );
	GFUserSignups::prep_signups_functionality();
	$activation_key = GFUserSignups::get_lead_activation_key( $entry_id );
	if ( $activation_key ) {
		GFUserSignups::delete_signup( $activation_key );
	}
} );

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_registration' ) ) {
		return;
	}

	$user_id = gf_user_registration()->get_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.