Last active
December 23, 2021 08:22
-
-
Save davewardle/250e41bfe264885378c0e6fd17417897 to your computer and use it in GitHub Desktop.
Updates retention policy for all existing Gravity Forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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