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