PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / trunk
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz vtrunk
2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / inc / single-form-settings / compliance-settings.php
sureforms / inc / single-form-settings Last commit date
compliance-settings.php 4 months ago form-settings-api.php 2 months ago
compliance-settings.php
103 lines
1 <?php
2 /**
3 * SureForms single form settings - Compliance settings.
4 *
5 * @package sureforms.
6 * @since 0.0.2
7 */
8
9 namespace SRFM\Inc\Single_Form_Settings;
10
11 use SRFM\Inc\Database\Tables\Entries;
12 use SRFM\Inc\Helper;
13 use SRFM\Inc\Traits\Get_Instance;
14
15 /**
16 * SureForms single form settings - Compliance settings.
17 *
18 * @since 0.0.2
19 */
20 class Compliance_Settings {
21 use Get_Instance;
22
23 /**
24 * Constructor
25 *
26 * @since 0.0.2
27 */
28 public function __construct() {
29 add_action( 'srfm_daily_scheduled_action', [ $this, 'pre_auto_delete_entries' ] );
30 }
31
32 /**
33 * Runs every 24 hours for SureForms.
34 * And check if auto delete entries are enabled for any forms.
35 * If enabled then delete the entries that are older than the days_old.
36 *
37 * @hooked - srfm_daily_scheduled_action
38 * @since 0.0.2
39 * @return void
40 */
41 public function pre_auto_delete_entries() {
42
43 // Get all the sureforms form post ids.
44 $form_ids = [];
45
46 $args = [
47 'post_type' => 'sureforms_form',
48 'posts_per_page' => -1,
49 'fields' => 'ids',
50 ];
51
52 $form_ids = get_posts( $args );
53
54 if ( empty( $form_ids ) ) {
55 return;
56 }
57
58 // For each form post id check if auto_delete_entries is enabled. If enabled then delete the entries that are older than the days_old.
59 foreach ( $form_ids as $form_id ) {
60 $compliance_settings = get_post_meta( $form_id, '_srfm_compliance', true );
61
62 $gdpr = false;
63 $do_not_store_entries = false;
64 $is_auto_delete_entries = false;
65 $days_old = 0;
66
67 if ( is_array( $compliance_settings ) && ! empty( $compliance_settings[0] ) && is_array( $compliance_settings[0] ) && isset( $compliance_settings[0]['gdpr'], $compliance_settings[0]['do_not_store_entries'], $compliance_settings[0]['auto_delete_entries'] ) ) {
68 $gdpr = $compliance_settings[0]['gdpr'];
69 $do_not_store_entries = $compliance_settings[0]['do_not_store_entries'];
70 $is_auto_delete_entries = $compliance_settings[0]['auto_delete_entries'];
71 $days_old = $compliance_settings[0]['auto_delete_days'];
72 }
73
74 // Only delete entries if gdpr, is_auto_delete_entries are enabled and do_not_store_entries is not enabled.
75 if ( $gdpr && ! $do_not_store_entries && $is_auto_delete_entries ) {
76 self::delete_old_entries( $days_old, $form_id );
77 }
78 }
79 }
80
81 /**
82 * Delete all the entries that are older than the days_old.
83 *
84 * @param int $days_old Number of days old.
85 * @param int $form_id Form ID.
86 * @since 0.0.2
87 * @return void
88 */
89 public static function delete_old_entries( $days_old, $form_id ) {
90 $entries = Helper::get_entries_from_form_ids( $days_old, [ $form_id ] );
91
92 if ( ! is_array( $entries ) || empty( $entries ) ) {
93 return;
94 }
95
96 foreach ( $entries as $entry ) {
97 $entry_id = isset( $entry['ID'] ) ? Helper::get_integer_value( $entry['ID'] ) : 0;
98 Entries::delete( $entry_id );
99 }
100 }
101
102 }
103