There are cases when you want to allow your site visitors to add content to your WordPress blog from a front end form. The best (and easiest) way to accomplish this is to use Gravity Forms and our Gravity Forms + Custom Post Types Addon. For those that don’t know, the addon allows your site visitors to capture custom post types from a front end Gravity Form.
So if your form is creating posts in your WordPress database, do you really need the form to also create an entry? (or a lead as it’s called in the Gravity Forms code). I think in most cases not.
Someone also asked me if I could stop Gravity Forms from creating these entry database records, so I looked into it. I could not find a way, using the existing Gravity Forms hooks, to stop the form from creating an entry/lead in the database.
But then someone pointed me towards a comment on a recent article written on yoast.com, and Simon provided a link to some code in pastebin which does exactly what we want. It deletes all the associated entry/lead data after the form has been submitted. Admittedly, it would be better to not insert the data into the database in the first place, but after looking into the code as mentioned above, that is not possible. So this is a great solution!
Here is the code:
2 things to note with the code:
- line 2 has a syntax error and has an unnecessaryparenthesis ‘)’
- the code will delete ALL entries for ALL forms. Please read the code comments to see how to target specific forms.
So now the question: Should I create a small plugin that does this? And include a settings page where you can configure which forms delete their entries/leads?