display-conditions
5 years ago
front
5 years ago
helpers
5 years ago
metas
5 years ago
palettes
5 years ago
provider
5 years ago
providers
5 years ago
templates
5 years ago
update
5 years ago
class-hustle-admin-page-abstract.php
5 years ago
class-hustle-condition-factory.php
6 years ago
class-hustle-dashboard-admin.php
5 years ago
class-hustle-data.php
5 years ago
class-hustle-db.php
6 years ago
class-hustle-module-admin.php
5 years ago
class-hustle-module-collection.php
5 years ago
class-hustle-module-decorator.php
5 years ago
class-hustle-module-page-abstract.php
5 years ago
class-hustle-notifications.php
5 years ago
class-hustle-settings-admin.php
5 years ago
class-hustle-upsell-page.php
5 years ago
class-hustle-wp-dashboard-page.php
5 years ago
hustle-collection.php
6 years ago
hustle-deletion.php
5 years ago
hustle-embedded-admin.php
6 years ago
hustle-entries-admin.php
5 years ago
hustle-entry-model.php
5 years ago
hustle-general-data-protection.php
6 years ago
hustle-init.php
5 years ago
hustle-mail.php
5 years ago
hustle-meta.php
5 years ago
hustle-migration.php
5 years ago
hustle-model.php
5 years ago
hustle-module-model.php
5 years ago
hustle-module-widget-legacy.php
5 years ago
hustle-module-widget.php
5 years ago
hustle-modules-common-admin-ajax.php
5 years ago
hustle-popup-admin.php
6 years ago
hustle-providers-admin.php
5 years ago
hustle-providers.php
6 years ago
hustle-settings-admin-ajax.php
5 years ago
hustle-settings-page.php
5 years ago
hustle-slidein-admin.php
6 years ago
hustle-sshare-admin.php
5 years ago
hustle-sshare-model.php
5 years ago
hustle-tracking-model.php
5 years ago
opt-in-geo.php
5 years ago
opt-in-utils.php
5 years ago
opt-in-wpmudev-api.php
6 years ago
hustle-general-data-protection.php
461 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | die(); |
| 4 | } |
| 5 | |
| 6 | /** |
| 7 | * Class Hustle_General_Data_Protection |
| 8 | * |
| 9 | * @since 4.0.2 |
| 10 | */ |
| 11 | class Hustle_General_Data_Protection { |
| 12 | |
| 13 | /** |
| 14 | * Clean up interval in string |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | protected $cron_cleanup_interval; |
| 19 | |
| 20 | /** |
| 21 | * Privacy settings array |
| 22 | * |
| 23 | * @var array |
| 24 | */ |
| 25 | private static $_privacy_settings = array(); |
| 26 | |
| 27 | |
| 28 | public function __construct( $cron_cleanup_interval = 'hourly' ) { |
| 29 | $this->cron_cleanup_interval = $cron_cleanup_interval; |
| 30 | $this->init(); |
| 31 | } |
| 32 | |
| 33 | protected function init() { |
| 34 | |
| 35 | // for data removal / anonymize data |
| 36 | if ( ! wp_next_scheduled( 'hustle_general_data_protection_cleanup' ) ) { |
| 37 | wp_schedule_event( time(), $this->get_cron_cleanup_interval(), 'hustle_general_data_protection_cleanup' ); |
| 38 | } |
| 39 | |
| 40 | add_action( 'hustle_general_data_protection_cleanup', array( $this, 'personal_data_cleanup' ) ); |
| 41 | add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_eraser' ), 10 ); |
| 42 | add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporter' ), 10 ); |
| 43 | |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Append registered eraser to wp eraser |
| 48 | * |
| 49 | * @param array $erasers |
| 50 | * |
| 51 | * @since 4.0.2 |
| 52 | * |
| 53 | * @return array |
| 54 | */ |
| 55 | public function register_eraser( $erasers = array() ) { |
| 56 | $erasers['hustle-module-submissions'] = array( |
| 57 | 'eraser_friendly_name' => __( 'Hustle Module Submissions', 'hustle' ), |
| 58 | 'callback' => array( 'Hustle_General_Data_Protection', 'do_submissions_eraser' ), |
| 59 | ); |
| 60 | return $erasers; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Append registered eraser to wp eraser |
| 65 | * |
| 66 | * @param array $erasers |
| 67 | * |
| 68 | * @since 4.0.2 |
| 69 | * |
| 70 | * @return array |
| 71 | */ |
| 72 | public function register_exporter( $exporter = array() ) { |
| 73 | $exporter['hustle-module-submissions'] = array( |
| 74 | 'exporter_friendly_name' => __( 'Hustle Module Submissions', 'hustle' ), |
| 75 | 'callback' => array( 'Hustle_General_Data_Protection', 'do_submissions_exporter' ), |
| 76 | ); |
| 77 | return $exporter; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Get Interval |
| 82 | * |
| 83 | * @since 4.0.2 |
| 84 | * |
| 85 | * @return string |
| 86 | */ |
| 87 | public function get_cron_cleanup_interval() { |
| 88 | $cron_cleanup_interval = $this->cron_cleanup_interval; |
| 89 | |
| 90 | /** |
| 91 | * Filter interval to be used for cleanup process |
| 92 | * |
| 93 | * @since 4.0.2 |
| 94 | * |
| 95 | * @params string $cron_cleanup_interval interval in string (daily,hourly, etc) |
| 96 | */ |
| 97 | $cron_cleanup_interval = apply_filters( 'hustle_general_data_cleanup_interval', $cron_cleanup_interval ); |
| 98 | |
| 99 | return $cron_cleanup_interval; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Eraser |
| 104 | * |
| 105 | * @since 4.0.2 |
| 106 | * |
| 107 | * @param $email |
| 108 | * @param $page |
| 109 | * |
| 110 | * @return array |
| 111 | */ |
| 112 | public static function do_submissions_eraser( $email, $page ) { |
| 113 | |
| 114 | $settings = self::_get_privacy_settings(); |
| 115 | |
| 116 | $erasure_disabled = '1' === $settings['retain_sub_on_erasure']; |
| 117 | |
| 118 | $response = array( |
| 119 | 'items_removed' => false, |
| 120 | 'items_retained' => true, |
| 121 | 'messages' => array(), |
| 122 | 'done' => true, |
| 123 | ); |
| 124 | |
| 125 | if ( true === $erasure_disabled ) { |
| 126 | |
| 127 | $response['messages'][] = __( 'Hustle submissions were retained.', 'hustle' ); |
| 128 | return $response; |
| 129 | } |
| 130 | |
| 131 | $entry_ids = Hustle_Entry_Model::get_entries_by_email( $email ); |
| 132 | |
| 133 | // using action instead of filter here to stop data manipulation |
| 134 | do_action( 'hustle_before_submission_eraser', $email, $page, $entry_ids ); |
| 135 | |
| 136 | if ( ! empty( $entry_ids ) ) { |
| 137 | foreach ( $entry_ids as $entry_id ) { |
| 138 | $entry_model = new Hustle_Entry_Model( $entry_id ); |
| 139 | Hustle_Entry_Model::delete_by_entry( $entry_model->module_id, $entry_id ); |
| 140 | $response['messages'][] = sprintf( __( 'Hustle submission #%d was deleted.', 'hustle' ), $entry_id ); |
| 141 | |
| 142 | } |
| 143 | $response['items_removed'] = true; |
| 144 | $response['items_retained'] = false; |
| 145 | } else { |
| 146 | $response['messages'][] = __( ' Hustle submissions not found.', 'hustle' ); |
| 147 | } |
| 148 | |
| 149 | // using action instead of filter here to stop data manipulation |
| 150 | do_action( 'hustle_after_submission_eraser', $email, $page, $entry_ids ); |
| 151 | |
| 152 | return $response; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Export module submissions |
| 157 | * |
| 158 | * @since 4.0.2 |
| 159 | * |
| 160 | * @param $email |
| 161 | * @param $page |
| 162 | * |
| 163 | * @return array |
| 164 | */ |
| 165 | public static function do_submissions_exporter( $email, $page ) { |
| 166 | $entry_ids = Hustle_Entry_Model::get_entries_by_email( $email ); |
| 167 | $data_to_export = array(); |
| 168 | |
| 169 | if ( ! empty( $entry_ids ) && is_array( $entry_ids ) ) { |
| 170 | foreach ( $entry_ids as $entry_id ) { |
| 171 | $entry_model = new Hustle_Entry_Model( $entry_id ); |
| 172 | |
| 173 | $data = array(); |
| 174 | |
| 175 | if ( is_object( $entry_model ) ) { |
| 176 | $data = self::get_custom_form_export_mappers( $entry_model ); |
| 177 | } |
| 178 | |
| 179 | $data_to_export[] = array( |
| 180 | 'group_id' => 'hustle_module_submissions', |
| 181 | 'group_label' => __( 'Hustle Module Submissions', 'hustle' ), |
| 182 | 'item_id' => 'entry-' . $entry_id, |
| 183 | 'data' => $data, |
| 184 | ); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Filter Export data for Custom form submission on tools.php?page=export_personal_data |
| 190 | * |
| 191 | * @since 4.0.2 |
| 192 | * |
| 193 | * @param array $data_to_export |
| 194 | * @param string $email |
| 195 | * @param array $entry_ids |
| 196 | */ |
| 197 | $data_to_export = apply_filters( 'hustle_module_submissions_export_data', $data_to_export, $email, $entry_ids ); |
| 198 | |
| 199 | return array( |
| 200 | 'data' => $data_to_export, |
| 201 | 'done' => true, |
| 202 | ); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Get data mappers and their values |
| 207 | * |
| 208 | * @since 4.0.2 |
| 209 | * |
| 210 | * @param Hustle_Entry_Model $model |
| 211 | * |
| 212 | * @return array |
| 213 | */ |
| 214 | public static function get_custom_form_export_mappers( $model ) { |
| 215 | |
| 216 | $ignored_field_types = Hustle_Entry_Model::ignored_fields(); |
| 217 | $meta = $model->meta_data; |
| 218 | |
| 219 | $mappers = array( |
| 220 | array( |
| 221 | 'name' => __( 'Entry ID', 'hustle' ), |
| 222 | 'value' => $model->entry_id, |
| 223 | ), |
| 224 | array( |
| 225 | 'name' => __( 'Submission Date', 'hustle' ), |
| 226 | 'value' => $model->date_created_sql, |
| 227 | ), |
| 228 | ); |
| 229 | |
| 230 | if ( ! empty( $meta ) ) { |
| 231 | foreach ( $meta as $key => $value ) { |
| 232 | // base mapper for every field |
| 233 | if ( is_array( $value['value'] ) ) { |
| 234 | continue; |
| 235 | } |
| 236 | |
| 237 | $mapper = array(); |
| 238 | $mapper['meta_key'] = $key; |
| 239 | $mapper['name'] = $key; |
| 240 | $mapper['value'] = $value['value']; |
| 241 | |
| 242 | if ( ! empty( $mapper ) ) { |
| 243 | $mappers[] = $mapper; |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return $mappers; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Anonymizing data |
| 253 | * |
| 254 | * @since 4.0.2 |
| 255 | * |
| 256 | * @return bool |
| 257 | */ |
| 258 | public function personal_data_cleanup() { |
| 259 | |
| 260 | $settings = self::_get_privacy_settings(); |
| 261 | |
| 262 | $this->_cleanup_submissions( $settings ); |
| 263 | $this->_cleanup_ip_address( $settings ); |
| 264 | $this->_cleanup_tracking_data( $settings ); |
| 265 | |
| 266 | return true; |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Clean up form submissions |
| 271 | * |
| 272 | * @since 4.0.2 |
| 273 | * |
| 274 | * @param privacy settings $settings |
| 275 | * |
| 276 | * @return bool |
| 277 | */ |
| 278 | private function _cleanup_submissions( $settings ) { |
| 279 | |
| 280 | $retain_number = $settings['submissions_retention_number']; |
| 281 | $retain_unit = $settings['submissions_retention_number_unit']; |
| 282 | |
| 283 | if ( '1' === $settings['retain_submission_forever'] || 0 === $retain_number ) { |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | $possible_units = array( |
| 288 | 'days', |
| 289 | 'weeks', |
| 290 | 'months', |
| 291 | 'years', |
| 292 | ); |
| 293 | |
| 294 | if ( ! in_array( $retain_unit, $possible_units, true ) ) { |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | $retain_time = strtotime( '-' . $retain_number . ' ' . $retain_unit, current_time( 'timestamp' ) ); |
| 299 | $retain_time = date_i18n( 'Y-m-d H:i:s', $retain_time ); |
| 300 | |
| 301 | $entry_ids = Hustle_Entry_Model::get_older_entry_ids( $retain_time ); |
| 302 | |
| 303 | foreach ( $entry_ids as $entry_id ) { |
| 304 | $entry_model = new Hustle_Entry_Model( $entry_id ); |
| 305 | Hustle_Entry_Model::delete_by_entry( $entry_model->module_id, $entry_id ); |
| 306 | } |
| 307 | |
| 308 | return true; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Cleanup IP Address based on settings |
| 313 | * |
| 314 | * @since 4.0.2 |
| 315 | * |
| 316 | * @param privacy settings $settings |
| 317 | * |
| 318 | * @return bool |
| 319 | */ |
| 320 | private function _cleanup_ip_address( $settings ) { |
| 321 | |
| 322 | $retain_number = $settings['ip_retention_number']; |
| 323 | $retain_unit = $settings['ip_retention_number_unit']; |
| 324 | |
| 325 | if ( '1' === $settings['retain_ip_forever'] || 0 === $retain_number ) { |
| 326 | return false; |
| 327 | } |
| 328 | |
| 329 | $possible_units = array( |
| 330 | 'days', |
| 331 | 'weeks', |
| 332 | 'months', |
| 333 | 'years', |
| 334 | ); |
| 335 | |
| 336 | if ( ! in_array( $retain_unit, $possible_units, true ) ) { |
| 337 | return false; |
| 338 | } |
| 339 | |
| 340 | $retain_time = strtotime( '-' . $retain_number . ' ' . $retain_unit, current_time( 'timestamp' ) ); |
| 341 | $retain_time = date_i18n( 'Y-m-d H:i:s', $retain_time ); |
| 342 | |
| 343 | $entry_ids = Hustle_Entry_Model::get_older_entry_ids( $retain_time ); |
| 344 | $tracking_ids = Hustle_Tracking_Model::get_older_tracking_ids( $retain_time ); |
| 345 | |
| 346 | foreach ( $entry_ids as $entry_id ) { |
| 347 | $entry_model = new Hustle_Entry_Model( $entry_id ); |
| 348 | $this->_anonymize_entry_model( $entry_model ); |
| 349 | } |
| 350 | |
| 351 | foreach ( $tracking_ids as $tracking_id ) { |
| 352 | $this->_anonymize_tracking_model( $tracking_id ); |
| 353 | } |
| 354 | |
| 355 | return true; |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Anon Entry model IP |
| 360 | * |
| 361 | * @since 4.0.2 |
| 362 | * |
| 363 | * @param Hustle_Entry_Model $entry_model |
| 364 | */ |
| 365 | private function _anonymize_entry_model( Hustle_Entry_Model $entry_model ) { |
| 366 | if ( isset( $entry_model->meta_data['hustle_ip'] ) ) { |
| 367 | $meta_id = $entry_model->meta_data['hustle_ip']['id']; |
| 368 | $meta_value = $entry_model->meta_data['hustle_ip']['value']; |
| 369 | |
| 370 | if ( function_exists( 'wp_privacy_anonymize_ip' ) ) { |
| 371 | $anon_value = wp_privacy_anonymize_ip( $meta_value ); |
| 372 | } else { |
| 373 | $anon_value = ''; |
| 374 | } |
| 375 | |
| 376 | if ( $anon_value !== $meta_value ) { |
| 377 | $entry_model->update_meta( $meta_id, 'hustle_ip', $anon_value ); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Cleanup tracking data |
| 384 | * |
| 385 | * @since 4.0.2 |
| 386 | * @param privacy settings $settings |
| 387 | * @return bool |
| 388 | */ |
| 389 | private function _cleanup_tracking_data( $settings ) { |
| 390 | |
| 391 | $retain_number = $settings['tracking_retention_number']; |
| 392 | $retain_unit = $settings['tracking_retention_number_unit']; |
| 393 | |
| 394 | if ( '1' === $settings['retain_tracking_forever'] || 0 === $retain_number ) { |
| 395 | return false; |
| 396 | } |
| 397 | |
| 398 | $possible_units = array( |
| 399 | 'days', |
| 400 | 'weeks', |
| 401 | 'months', |
| 402 | 'years', |
| 403 | ); |
| 404 | |
| 405 | if ( ! in_array( $retain_unit, $possible_units, true ) ) { |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | $retain_time = strtotime( '-' . $retain_number . ' ' . $retain_unit, current_time( 'timestamp' ) ); |
| 410 | $retain_time = date_i18n( 'Y-m-d H:i:s', $retain_time ); |
| 411 | |
| 412 | $tracking_ids = Hustle_Tracking_Model::get_older_tracking_ids( $retain_time ); |
| 413 | |
| 414 | foreach ( $tracking_ids as $tracking_id ) { |
| 415 | Hustle_Tracking_Model::delete_data_by_tracking_id( $tracking_id ); |
| 416 | } |
| 417 | |
| 418 | return true; |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Get privacy settings |
| 423 | * |
| 424 | * @since 4.0.2 |
| 425 | * |
| 426 | * @return settings array() |
| 427 | */ |
| 428 | private static function _get_privacy_settings() { |
| 429 | if ( empty( self::$_privacy_settings ) ) { |
| 430 | self::$_privacy_settings = Hustle_Settings_Admin::get_privacy_settings(); |
| 431 | } |
| 432 | return self::$_privacy_settings; |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * Anon Tracking model IP |
| 437 | * |
| 438 | * @since 4.0.2 |
| 439 | * |
| 440 | * @param tracking id $tracking |
| 441 | */ |
| 442 | private function _anonymize_tracking_model( $tracking ) { |
| 443 | if ( ! empty( $tracking ) ) { |
| 444 | |
| 445 | $ip = Hustle_Tracking_Model::get_ip_from_tracking_id( $tracking ); |
| 446 | |
| 447 | if ( ! empty( $ip ) ) { |
| 448 | |
| 449 | if ( function_exists( 'wp_privacy_anonymize_ip' ) ) { |
| 450 | $anon_value = wp_privacy_anonymize_ip( $ip[0] ); |
| 451 | } else { |
| 452 | $anon_value = ''; |
| 453 | } |
| 454 | |
| 455 | Hustle_Tracking_Model::anonymise_tracked_id( $tracking, $anon_value ); |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | } |
| 461 |