Deleting the entry (using GFAPI::delete_entry) that's just been saved causes critical error [RESOLVED]

In some cases I need to delete an entry as soon as it’s been saved and certain elements processed. I use the hook gform_after_submission to do what needs to be done and then at the end of the function call

GFAPI::delete_entry( $entry_id );

This works (the entry does get deleted) but it then produces a critical error. The first part of the long error message (with WP_DEBUG turned on) is:

Uncaught Error: Cannot use object of type WP_Error as array in /var/www/html/

What I suspect is going on is the Gravity View code is looking for the entry to do something more with it and not finding it.

Does anyone have any ideas how to get around this? I tried using the hook gform_post_process and that produced the same error.


I recommend reporting this issue to GravityKit, so they can look into catching that error.

The problem you’re encountering is that Gravity View tries to work with an entry you’ve already deleted. To fix this, we can modify your code slightly so that Gravity View can access the entry before it gets deleted.

Here’s a modified version of your code that should help:

// First, we'll add our custom function to run after the form submission
add_action('gform_after_submission', 'process_and_delete_entry', 10, 2);

function process_and_delete_entry($entry, $form) {
    // Do the necessary processing with the entry here

    // Schedule the entry deletion to happen just before it's actually deleted
    add_action('gform_delete_lead', 'delete_the_entry', 10, 1);
    function delete_the_entry($entry_id) {

    // Now, let's trigger the deletion process
    do_action('gform_delete_lead', $entry['id']);

This code will first let Gravity View work with the entry and then delete it afterward. If you still encounter issues, you can try adjusting the priority of your action by changing the number 10 to a higher value, like 100:

add_action('gform_after_submission', 'process_and_delete_entry', 100, 2);

This will give Gravity View more time to finish its work before your custom code starts running.

Thanks for reporting this issue, @user5e5f0c0318fd3879! This will be fixed in the next update.

If you want to run a pre-release version (that should be stable), you can download it here.

If you find any other issues in GravityView, please reach out to us at We’re here to help!

Thank you all. I wasn’t sure if this was truly a bug. It sounds like it is. For the moment I’ve decided to just move the entries to the trash rather than delete it, but it’s good to know that the delete option is available.

And thank you, Faisal, for the work-around. That’s a good solution to have in my back pocket.

1 Like