PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.26
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.26
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.26, at classes/models/FrmPersonalData.php

204 lines 4.4 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 ( empty( $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 ( empty( $email ) ) {
108 return $data_removed;
109 }
110
111 $this->page = absint( $page );
112 $entries = $this->get_user_entries( $email );
113
114 if ( empty( $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
151 $entries_by_email = FrmDb::get_col( 'frm_item_metas', array( 'meta_value' => $email ), 'item_id', $query_args );
152
153 if ( empty( $user ) ) {
154 // no matching user, so return the entry ids we have
155 return $entries_by_email;
156 }
157
158 $query_args['order_by'] = 'id ASC';
159
160 $entries_by_user = FrmDb::get_col( 'frm_items', array( 'user_id' => $user->ID ), 'id', $query_args );
161
162 $entry_ids = array_merge( $entries_by_user, $entries_by_email );
163 $entry_ids = array_unique( array_filter( $entry_ids ) );
164
165 return $entry_ids;
166 }
167
168 /**
169 * @return string
170 */
171 private function get_current_page() {
172 $start = ( $this->page - 1 ) * $this->limit;
173
174 return FrmDb::esc_limit( $start . ',' . $this->limit );
175 }
176
177 /**
178 * @param int $entry
179 *
180 * @return array
181 */
182 private function prepare_entry_data( $entry ) {
183 $entry = FrmEntry::getOne( $entry, true );
184
185 $entry_data = array();
186
187 foreach ( $entry->metas as $field_id => $meta ) {
188 $field = FrmField::getOne( $field_id );
189
190 $entry_data[] = array(
191 'name' => $field->name,
192 'value' => FrmFieldsHelper::get_unfiltered_display_value(
193 array(
194 'field' => $field,
195 'value' => $meta,
196 )
197 ),
198 );
199 }
200
201 return $entry_data;
202 }
203 }
204