Default retention policy for auto-deleting entries [RESOLVED]

Is there any way of setting a default entry retention policy for all new forms so that whenever someone creates a new form it already has the retention policy setting active (for example “delete entries permanently after 30 days”)?

I would like a global retention policy setting for all my forms as I have multiple people creating forms on a relatively large multisite and some may forget to turn on retention policy for their new form despite being instructed to do so which could potentially be a serious problem as some form entries will contain personal data which should be deleted from the database after a time.

Luckily we were able to figure this out ourselves.

If anyone else is wondering how to set “default retention policy” for all newly created forms you can use this code snippet (place in functions.php file of your theme):

add_action( 'gform_after_save_form', 'default_retention_policy_for_gforms', 10, 2 );

function default_retention_policy_for_gforms( $form, $is_new ) {
	if ( $is_new ) {
		$form['personalData']['retention']['policy'] = 'delete'; // Retention policy: retain, trash or delete
		$form['personalData']['retention']['retain_entries_days'] = 30; // The number of days to retain entries

		GFAPI::update_form( $form );
	}
}

Above code automatically sets retention policy to delete and retains entries for 30 days before deleting them for all new forms (doesn’t affect “old” forms).