PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.29
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.29
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / FrmPersonalData.php

FrmPersonalData.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.29, at classes/models/FrmPersonalData.php

198 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmPersonalData {
7
8 /**
9 * @var int
10 */
11 private $limit = 200;
12
13 /**
14 * @var int
15 */
16 private $page = 1;
17
18 public function __construct() {
19 add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_data_eraser' ) );
20 add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporter' ) );
21 }
22
23 /**
24 * Add options to the WordPress personal data exporter
25 *
26 * @since 3.02
27 *
28 * @param array $exporters
29 *
30 * @return array
31 */
32 public function register_exporter( $exporters ) {
33 $exporters['formidable-exporter'] = array(
34 'exporter_friendly_name' => __( 'Formidable Forms Exporter', 'formidable' ),
35 'callback' => array( $this, 'export_data' ),
36 );
37
38 return $exporters;
39 }
40
41 /**
42 * Add options to the WordPress personal data eraser
43 *
44 * @since 3.02
45 *
46 * @param array $erasers
47 *
48 * @return array
49 */
50 public function register_data_eraser( $erasers ) {
51 $erasers['formidable-eraser'] = array(
52 'eraser_friendly_name' => __( 'Formidable Forms entries', 'formidable' ),
53 'callback' => array( $this, 'erase_data' ),
54 );
55
56 return $erasers;
57 }
58
59 /**
60 * @param string $email
61 * @param int $page
62 *
63 * @return array
64 */
65 public function export_data( $email, $page = 1 ) {
66 $this->page = absint( $page );
67
68 $data_to_export = array(
69 'data' => array(),
70 'done' => true,
71 );
72
73 $entries = $this->get_user_entries( $email );
74
75 if ( ! $entries ) {
76 return $data_to_export;
77 }
78
79 foreach ( $entries as $entry ) {
80 $data_to_export['data'][] = array(
81 'group_id' => 'formidable',
82 'group_label' => __( 'Form Submissions', 'formidable' ),
83 'item_id' => esc_attr( 'entry-' . $entry ),
84 'data' => $this->prepare_entry_data( $entry ),
85 );
86 }
87
88 $data_to_export['done'] = count( $entries ) < $this->limit;
89
90 return $data_to_export;
91 }
92
93 /**
94 * @param string $email
95 * @param int $page
96 *
97 * @return array
98 */
99 public function erase_data( $email, $page = 1 ) {
100 $data_removed = array(
101 'items_removed' => false,
102 'items_retained' => false,
103 'messages' => array(),
104 'done' => true,
105 );
106
107 if ( ! $email ) {
108 return $data_removed;
109 }
110
111 $this->page = absint( $page );
112 $entries = $this->get_user_entries( $email );
113
114 if ( ! $entries ) {
115 return $data_removed;
116 }
117
118 // TODO: Add an option to anonymize the entries with wp_privacy_anonymize_data( 'email', 'e@e.com' );
119
120 foreach ( $entries as $entry ) {
121 $removed = FrmEntry::destroy( $entry );
122
123 if ( $removed ) {
124 $data_removed['items_removed'] = true;
125 } else {
126 $data_removed['items_retained'] = true;
127 }
128 }
129
130 $data_removed['done'] = count( $entries ) < $this->limit;
131
132 return $data_removed;
133 }
134
135 /**
136 * Get all entries that were submitted by this user while logged in,
137 * or with a field value that matches the email address
138 *
139 * @param string $email
140 *
141 * @return array Entry ids
142 */
143 private function get_user_entries( $email ) {
144 $query_args = array(
145 'order_by' => 'item_id ASC',
146 'limit' => $this->get_current_page(),
147 );
148
149 $user = get_user_by( 'email', $email );
150 $entries_by_email = FrmDb::get_col( 'frm_item_metas', array( 'meta_value' => $email ), 'item_id', $query_args );
151
152 if ( ! $user ) {
153 // No matching user, so return the entry ids we have
154 return $entries_by_email;
155 }
156
157 $query_args['order_by'] = 'id ASC';
158 $entries_by_user = FrmDb::get_col( 'frm_items', array( 'user_id' => $user->ID ), 'id', $query_args );
159 $entry_ids = array_merge( $entries_by_user, $entries_by_email );
160
161 return array_unique( array_filter( $entry_ids ) );
162 }
163
164 /**
165 * @return string
166 */
167 private function get_current_page() {
168 $start = ( $this->page - 1 ) * $this->limit;
169 return FrmDb::esc_limit( $start . ',' . $this->limit );
170 }
171
172 /**
173 * @param int $entry
174 *
175 * @return array
176 */
177 private function prepare_entry_data( $entry ) {
178 $entry = FrmEntry::getOne( $entry, true );
179 $entry_data = array();
180
181 foreach ( $entry->metas as $field_id => $meta ) {
182 $field = FrmField::getOne( $field_id );
183
184 $entry_data[] = array(
185 'name' => $field->name,
186 'value' => FrmFieldsHelper::get_unfiltered_display_value(
187 array(
188 'field' => $field,
189 'value' => $meta,
190 )
191 ),
192 );
193 }
194
195 return $entry_data;
196 }
197 }
198