PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.8.9
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.8.9
7.8.14 7.8.14.1 7.8.13 7.8.13.1 trunk 3.0 3.1 3.1.1 3.1.2 3.1.3 3.1.4 4.3.2 4.4.4 4.4.5 4.4.5.1 4.4.5.4 4.6 4.6.1.1 4.6.1.4 4.7.0.2 4.7.0.3 4.7.0.7 4.7.0.9 4.7.1.0 4.7.1.1 4.8.0.0 5.0.0 5.0.1 5.0.1.1 5.0.1.2 5.1 5.1.1 5.1.2 5.1.3 5.1.3.1 5.1.3.2 5.1.4 5.1.5 6.0 6.0.1 6.0.2 6.0.3 6.0.4.2 6.0.5 6.0.6.1 6.0.7 6.0.8.1 6.0.9 7.0.0.1 7.0.2 7.0.3 7.0.4 7.1.0 7.1.1 7.2.0 7.2.1 7.3.0 7.3.1 7.3.3 7.3.5 7.3.6 7.3.7 7.4.0 7.4.1 7.4.11 7.4.13 7.4.13.1 7.4.2 7.4.3 7.4.4 7.4.5 7.4.5.1 7.4.5.2 7.4.6 7.4.7 7.5.0 7.6.0 7.6.1 7.6.3 7.6.4 7.6.6 7.7.0 7.7.1 7.8.0 7.8.1 7.8.10 7.8.10.1 7.8.10.2 7.8.11 7.8.12 7.8.12.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.8.9.1 7.8.9.2 7.8.9.3
wordpress-popup / inc / hustle-general-data-protection.php
wordpress-popup / inc Last commit date
display-conditions 3 years ago front 10 months ago helpers 10 months ago metas 3 years ago multisite 3 years ago palettes 3 years ago provider 3 years ago providers 10 months ago templates 3 years ago update 3 years ago class-hustle-admin-page-abstract.php 10 months ago class-hustle-black-friday-campaign.php 7 months ago class-hustle-condition-factory.php 6 years ago class-hustle-cross-sell.php 10 months ago class-hustle-dashboard-admin.php 3 years ago class-hustle-data.php 3 years ago class-hustle-db.php 2 years ago class-hustle-installer.php 4 years ago class-hustle-meta.php 3 years ago class-hustle-module-admin.php 10 months ago class-hustle-module-collection.php 3 years ago class-hustle-module-page-abstract.php 2 years ago class-hustle-notifications.php 3 years ago class-hustle-settings-admin.php 3 years ago class-hustle-tutorials-page.php 4 years ago class-hustle-wp-dashboard-page.php 3 years ago hustle-deletion.php 3 years ago hustle-embedded-admin.php 3 years ago hustle-entries-admin.php 3 years ago hustle-entry-model.php 3 years ago hustle-general-data-protection.php 3 years ago hustle-init.php 7 months ago hustle-mail.php 3 years ago hustle-migration.php 3 years ago hustle-model.php 3 years ago hustle-module-model.php 10 months ago hustle-module-widget-legacy.php 3 years ago hustle-module-widget.php 3 years ago hustle-modules-common-admin-ajax.php 10 months ago hustle-popup-admin.php 3 years ago hustle-providers-admin.php 3 years ago hustle-providers.php 3 years ago hustle-settings-admin-ajax.php 3 years ago hustle-settings-page.php 3 years ago hustle-slidein-admin.php 3 years ago hustle-sshare-admin.php 3 years ago hustle-sshare-model.php 3 years ago hustle-tracking-model.php 3 years ago opt-in-geo.php 10 months ago opt-in-utils.php 3 years ago opt-in-wpmudev-api.php 3 years ago
hustle-general-data-protection.php
476 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Hustle_General_Data_Protection
4 *
5 * @package Hustle
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 die();
10 }
11
12 /**
13 * Class Hustle_General_Data_Protection
14 *
15 * @since 4.0.2
16 */
17 class Hustle_General_Data_Protection {
18
19 /**
20 * Clean up interval in string
21 *
22 * @var string
23 */
24 protected $cron_cleanup_interval;
25
26 /**
27 * Privacy settings array
28 *
29 * @var array
30 */
31 private static $privacy_settings = array();
32
33 /**
34 * Constructor.
35 *
36 * @param string $cron_cleanup_interval Cron interval.
37 */
38 public function __construct( $cron_cleanup_interval = 'hourly' ) {
39 $this->cron_cleanup_interval = $cron_cleanup_interval;
40 $this->init();
41 }
42
43 /**
44 * Init
45 */
46 protected function init() {
47
48 // for data removal / anonymize data.
49 if ( ! wp_next_scheduled( 'hustle_general_data_protection_cleanup' ) ) {
50 wp_schedule_event( time(), $this->get_cron_cleanup_interval(), 'hustle_general_data_protection_cleanup' );
51 }
52
53 add_action( 'hustle_general_data_protection_cleanup', array( $this, 'personal_data_cleanup' ) );
54 add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_eraser' ), 10 );
55 add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporter' ), 10 );
56
57 }
58
59 /**
60 * Append registered eraser to wp eraser
61 *
62 * @param array $erasers Erasers.
63 *
64 * @since 4.0.2
65 *
66 * @return array
67 */
68 public function register_eraser( $erasers = array() ) {
69 $erasers['hustle-module-submissions'] = array(
70 /* translators: Plugin name */
71 'eraser_friendly_name' => esc_html( sprintf( __( '%s Module Submissions', 'hustle' ), Opt_In_Utils::get_plugin_name() ) ),
72 'callback' => array( 'Hustle_General_Data_Protection', 'do_submissions_eraser' ),
73 );
74 return $erasers;
75 }
76
77 /**
78 * Append registered eraser to wp eraser
79 *
80 * @param array $exporter Exporter.
81 *
82 * @since 4.0.2
83 *
84 * @return array
85 */
86 public function register_exporter( $exporter = array() ) {
87 $exporter['hustle-module-submissions'] = array(
88 'exporter_friendly_name' => /* translators: Plugin name */ esc_html( sprintf( __( '%s Module Submissions', 'hustle' ), Opt_In_Utils::get_plugin_name() ) ),
89 'callback' => array( 'Hustle_General_Data_Protection', 'do_submissions_exporter' ),
90 );
91 return $exporter;
92 }
93
94 /**
95 * Get Interval
96 *
97 * @since 4.0.2
98 *
99 * @return string
100 */
101 public function get_cron_cleanup_interval() {
102 $cron_cleanup_interval = $this->cron_cleanup_interval;
103
104 /**
105 * Filter interval to be used for cleanup process
106 *
107 * @since 4.0.2
108 *
109 * @params string $cron_cleanup_interval interval in string (daily,hourly, etc)
110 */
111 $cron_cleanup_interval = apply_filters( 'hustle_general_data_cleanup_interval', $cron_cleanup_interval );
112
113 return $cron_cleanup_interval;
114 }
115
116 /**
117 * Eraser
118 *
119 * @since 4.0.2
120 *
121 * @param string $email Email.
122 * @param int $page Page.
123 *
124 * @return array
125 */
126 public static function do_submissions_eraser( $email, $page ) {
127
128 $settings = self::get_privacy_settings();
129
130 $erasure_disabled = '1' === $settings['retain_sub_on_erasure'];
131
132 $response = array(
133 'items_removed' => false,
134 'items_retained' => true,
135 'messages' => array(),
136 'done' => true,
137 );
138
139 if ( true === $erasure_disabled ) {
140 /* translators: Plugin name */
141 $response['messages'][] = esc_html( sprintf( __( '%s Module Submissions were retained.', 'hustle' ), Opt_In_Utils::get_plugin_name() ) );
142 return $response;
143 }
144
145 $entry_ids = Hustle_Entry_Model::get_entries_by_email( $email );
146
147 // using action instead of filter here to stop data manipulation.
148 do_action( 'hustle_before_submission_eraser', $email, $page, $entry_ids );
149
150 if ( ! empty( $entry_ids ) ) {
151 foreach ( $entry_ids as $entry_id ) {
152 $entry_model = new Hustle_Entry_Model( $entry_id );
153 Hustle_Entry_Model::delete_by_entry( $entry_model->module_id, $entry_id );
154 /* translators: 1. Plugin name 2. entry id */
155 $response['messages'][] = esc_html( sprintf( __( '%1$s submission #%2$d was deleted.', 'hustle' ), Opt_In_Utils::get_plugin_name(), $entry_id ) );
156
157 }
158 $response['items_removed'] = true;
159 $response['items_retained'] = false;
160 } else {
161 /* translators: Plugin name */
162 $response['messages'][] = esc_html( sprintf( __( ' %s submissions not found.', 'hustle' ), Opt_In_Utils::get_plugin_name() ) );
163 }
164
165 // using action instead of filter here to stop data manipulation.
166 do_action( 'hustle_after_submission_eraser', $email, $page, $entry_ids );
167
168 return $response;
169 }
170
171 /**
172 * Export module submissions
173 *
174 * @since 4.0.2
175 *
176 * @param string $email Email.
177 * @param int $page Page.
178 *
179 * @return array
180 */
181 public static function do_submissions_exporter( $email, $page ) {
182 $entry_ids = Hustle_Entry_Model::get_entries_by_email( $email );
183 $data_to_export = array();
184
185 if ( ! empty( $entry_ids ) && is_array( $entry_ids ) ) {
186 foreach ( $entry_ids as $entry_id ) {
187 $entry_model = new Hustle_Entry_Model( $entry_id );
188
189 $data = array();
190
191 if ( is_object( $entry_model ) ) {
192 $data = self::get_custom_form_export_mappers( $entry_model );
193 }
194
195 $data_to_export[] = array(
196 'group_id' => 'hustle_module_submissions',
197 'group_label' => /* translators: Plugin name */ esc_html( sprintf( __( '%s Module Submissions', 'hustle' ), Opt_In_Utils::get_plugin_name() ) ),
198 'item_id' => 'entry-' . $entry_id,
199 'data' => $data,
200 );
201 }
202 }
203
204 /**
205 * Filter Export data for Custom form submission on tools.php?page=export_personal_data
206 *
207 * @since 4.0.2
208 *
209 * @param array $data_to_export
210 * @param string $email
211 * @param array $entry_ids
212 */
213 $data_to_export = apply_filters( 'hustle_module_submissions_export_data', $data_to_export, $email, $entry_ids );
214
215 return array(
216 'data' => $data_to_export,
217 'done' => true,
218 );
219 }
220
221 /**
222 * Get data mappers and their values
223 *
224 * @since 4.0.2
225 *
226 * @param Hustle_Entry_Model $model Model.
227 *
228 * @return array
229 */
230 public static function get_custom_form_export_mappers( $model ) {
231
232 $meta = $model->meta_data;
233
234 $mappers = array(
235 array(
236 'name' => __( 'Entry ID', 'hustle' ),
237 'value' => $model->entry_id,
238 ),
239 array(
240 'name' => __( 'Submission Date', 'hustle' ),
241 'value' => $model->date_created_sql,
242 ),
243 );
244
245 if ( ! empty( $meta ) ) {
246 foreach ( $meta as $key => $value ) {
247 // base mapper for every field.
248 if ( is_array( $value['value'] ) ) {
249 continue;
250 }
251
252 $mapper = array();
253 $mapper['meta_key'] = $key;// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
254 $mapper['name'] = $key;
255 $mapper['value'] = $value['value'];
256
257 if ( ! empty( $mapper ) ) {
258 $mappers[] = $mapper;
259 }
260 }
261 }
262
263 return $mappers;
264 }
265
266 /**
267 * Anonymizing data
268 *
269 * @since 4.0.2
270 *
271 * @return bool
272 */
273 public function personal_data_cleanup() {
274
275 $settings = self::get_privacy_settings();
276
277 $this->cleanup_submissions( $settings );
278 $this->cleanup_ip_address( $settings );
279 $this->cleanup_tracking_data( $settings );
280
281 return true;
282 }
283
284 /**
285 * Clean up form submissions
286 *
287 * @since 4.0.2
288 *
289 * @param array $settings privacy settings.
290 *
291 * @return bool
292 */
293 private function cleanup_submissions( $settings ) {
294
295 $retain_number = $settings['submissions_retention_number'];
296 $retain_unit = $settings['submissions_retention_number_unit'];
297
298 if ( '1' === $settings['retain_submission_forever'] || 0 === $retain_number ) {
299 return false;
300 }
301
302 $possible_units = array(
303 'days',
304 'weeks',
305 'months',
306 'years',
307 );
308
309 if ( ! in_array( $retain_unit, $possible_units, true ) ) {
310 return false;
311 }
312
313 $retain_time = strtotime( '-' . $retain_number . ' ' . $retain_unit );
314 $retain_time = date_i18n( 'Y-m-d H:i:s', $retain_time );
315
316 $entry_ids = Hustle_Entry_Model::get_older_entry_ids( $retain_time );
317
318 foreach ( $entry_ids as $entry_id ) {
319 $entry_model = new Hustle_Entry_Model( $entry_id );
320 Hustle_Entry_Model::delete_by_entry( $entry_model->module_id, $entry_id );
321 }
322
323 return true;
324 }
325
326 /**
327 * Cleanup IP Address based on settings
328 *
329 * @since 4.0.2
330 *
331 * @param array $settings privacy settings.
332 *
333 * @return bool
334 */
335 private function cleanup_ip_address( $settings ) {
336
337 $retain_number = $settings['ip_retention_number'];
338 $retain_unit = $settings['ip_retention_number_unit'];
339
340 if ( '1' === $settings['retain_ip_forever'] || 0 === $retain_number ) {
341 return false;
342 }
343
344 $possible_units = array(
345 'days',
346 'weeks',
347 'months',
348 'years',
349 );
350
351 if ( ! in_array( $retain_unit, $possible_units, true ) ) {
352 return false;
353 }
354
355 $retain_time = strtotime( '-' . $retain_number . ' ' . $retain_unit );
356 $retain_time = date_i18n( 'Y-m-d H:i:s', $retain_time );
357
358 $entry_ids = Hustle_Entry_Model::get_older_entry_ids( $retain_time );
359 $tracking_ids = Hustle_Tracking_Model::get_older_tracking_ids( $retain_time );
360
361 foreach ( $entry_ids as $entry_id ) {
362 $entry_model = new Hustle_Entry_Model( $entry_id );
363 $this->anonymize_entry_model( $entry_model );
364 }
365
366 foreach ( $tracking_ids as $tracking_id ) {
367 $this->anonymize_tracking_model( $tracking_id );
368 }
369
370 return true;
371 }
372
373 /**
374 * Anon Entry model IP
375 *
376 * @since 4.0.2
377 *
378 * @param Hustle_Entry_Model $entry_model Entry model.
379 */
380 private function anonymize_entry_model( Hustle_Entry_Model $entry_model ) {
381 if ( isset( $entry_model->meta_data['hustle_ip'] ) ) {
382 $meta_id = $entry_model->meta_data['hustle_ip']['id'];
383 $meta_value = $entry_model->meta_data['hustle_ip']['value'];
384
385 if ( function_exists( 'wp_privacy_anonymize_ip' ) ) {
386 $anon_value = wp_privacy_anonymize_ip( $meta_value );
387 } else {
388 $anon_value = '';
389 }
390
391 if ( $anon_value !== $meta_value ) {
392 $entry_model->update_meta( $meta_id, 'hustle_ip', $anon_value );
393 }
394 }
395 }
396
397 /**
398 * Cleanup tracking data
399 *
400 * @since 4.0.2
401 * @param array $settings privacy settings.
402 * @return bool
403 */
404 private function cleanup_tracking_data( $settings ) {
405
406 $retain_number = $settings['tracking_retention_number'];
407 $retain_unit = $settings['tracking_retention_number_unit'];
408
409 if ( '1' === $settings['retain_tracking_forever'] || 0 === $retain_number ) {
410 return false;
411 }
412
413 $possible_units = array(
414 'days',
415 'weeks',
416 'months',
417 'years',
418 );
419
420 if ( ! in_array( $retain_unit, $possible_units, true ) ) {
421 return false;
422 }
423
424 $retain_time = strtotime( '-' . $retain_number . ' ' . $retain_unit );
425 $retain_time = date_i18n( 'Y-m-d H:i:s', $retain_time );
426
427 $tracking_ids = Hustle_Tracking_Model::get_older_tracking_ids( $retain_time );
428
429 foreach ( $tracking_ids as $tracking_id ) {
430 Hustle_Tracking_Model::delete_data_by_tracking_id( $tracking_id );
431 }
432
433 return true;
434 }
435
436 /**
437 * Get privacy settings
438 *
439 * @since 4.0.2
440 *
441 * @return settings array()
442 */
443 private static function get_privacy_settings() {
444 if ( empty( self::$privacy_settings ) ) {
445 self::$privacy_settings = Hustle_Settings_Admin::get_privacy_settings();
446 }
447 return self::$privacy_settings;
448 }
449
450 /**
451 * Anon Tracking model IP
452 *
453 * @since 4.0.2
454 *
455 * @param string $tracking tracking id.
456 */
457 private function anonymize_tracking_model( $tracking ) {
458 if ( ! empty( $tracking ) ) {
459
460 $ip = Hustle_Tracking_Model::get_ip_from_tracking_id( $tracking );
461
462 if ( ! empty( $ip ) ) {
463
464 if ( function_exists( 'wp_privacy_anonymize_ip' ) ) {
465 $anon_value = wp_privacy_anonymize_ip( $ip[0] );
466 } else {
467 $anon_value = '';
468 }
469
470 Hustle_Tracking_Model::anonymise_tracked_id( $tracking, $anon_value );
471 }
472 }
473 }
474
475 }
476