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

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