Hello! I now finished my MSc and graduated a few months ago (distinction, yay!) but I’m still as busy as ever. My wife recently gave birth to our second child and I’m snowed under with work (1, 2) – catching up on all the time I took off for my thesis. Anywho, hopefully today’s post will actually be useful for once. I did a quick search online and couldn’t find any similar code.
Gravity Forms, a very popular WordPress plugin, recently released an update that introduced a number of features to help assist website owners with GDPR compliance. One of these features is a new data retention policy setting that can:
- Prevent IP addresses from being stored.
- Automatically trash or permanently delete form entries.
- Allow for automatic export or deletion of specific field data.
Unfortunately, there is no way to define a global retention policy – it has to be done on a form by form basis. For web agencies, setting the policy on every form on every website would be a very time consuming task to say the least. So I have written a few lines of code that will do all the work for me.
This first snippet will update all existing forms with a new data retention policy (“don’t store IP address and delete after 45 days”) except those with an existing delete policy. I have hooked it onto
init as it is a quick and dirty function that should be executed once and then removed from the code base. If this is something that you would like to run on a regular basis then I’m sure there are much better hooks to use.
Now that all existing forms are updated, we want to make sure that the new policy is set for new forms:
Simply remove the
is_new condition if you would like this to run whenever a form is edited to ensure that the policy has not been changed.
Eagle eyed readers will notice that I haven’t done anything for the data export/erasure options. This one is a more complicated as it is dependent on the fields available. I guess it would be fairly easy to implement a select all approach by extending the above code.
Thanks for reading.