Skip to content

Instantly share code, notes, and snippets.

@davewardle davewardle/functions.php
Last active Jan 24, 2019

Embed
What would you like to do?
Updates retention policy for all existing Gravity Forms
<?php
function enforce_gravity_forms_retention_policy() {
// only load for admin panel
if ( is_admin() && class_exists( 'GFForms' ) ) {
// load all forms
$forms = GFAPI::get_forms();
// loop through each form
foreach ( $forms as $form ) {
// only modify forms without delete policy
if ( rgars( $form, 'personalData/retention/policy' ) !== 'delete' ) {
// set enforced rules
$form['personalData']['preventIP'] = true;
$form['personalData']['retention'] = [
'policy' => 'delete',
'retain_entries_days' => 45
];
// save form
GFAPI::update_form( $form );
}
}
}
}
add_action( 'init', 'enforce_gravity_forms_retention_policy', 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.