PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.3.6
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.3.6
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / admin / settings / miscellaneous-settings / class-wpsc-ms-gdpr.php

class-wpsc-ms-gdpr.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.3.6, at includes/admin/settings/miscellaneous-settings/class-wpsc-ms-gdpr.php

636 lines 20.9 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 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_MS_GDPR' ) ) :
7
8 final class WPSC_MS_GDPR {
9
10 /**
11 * Initialize this class
12 *
13 * @return void
14 */
15 public static function init() {
16
17 // User interface.
18 add_action( 'wp_ajax_wpsc_get_ms_gdpr', array( __CLASS__, 'load_settings_ui' ) );
19 add_action( 'wp_ajax_wpsc_set_ms_gdpr', array( __CLASS__, 'save_settings' ) );
20 add_action( 'wp_ajax_wpsc_reset_ms_gdpr', array( __CLASS__, 'reset_settings' ) );
21
22 // Print in create ticket form.
23 add_action( 'wpsc_print_tff', array( __CLASS__, 'print_tff' ) );
24
25 // TFF! validation.
26 add_action( 'wpsc_js_validate_ticket_form', array( __CLASS__, 'js_validate_ticket_form' ) );
27
28 // make tickets anonymous - gdpr setting.
29 add_action( 'wpsc_cron_daily', array( __CLASS__, 'personal_data_eraser' ) );
30
31 // GDPR.
32 add_filter( 'wp_privacy_personal_data_exporters', array( __CLASS__, 'wpsc_register_privacy_exporters' ) );
33 add_filter( 'wp_privacy_personal_data_erasers', array( __CLASS__, 'wpsc_register_privacy_erasers' ) );
34 }
35
36 /**
37 * Reset settings
38 *
39 * @return void
40 */
41 public static function reset() {
42
43 $gdpr_text = '<p>I understand my personal information like Name, Email address, IP address, etc. will be stored in database.</p>';
44 $gdpr = apply_filters(
45 'wpsc_gdpr_settings',
46 array(
47 'allow-gdpr' => 1,
48 'gdpr-text' => $gdpr_text,
49 'personal-data-retention-time' => 0,
50 'personal-data-retention-unit' => 'days',
51 'editor' => 'html',
52 'allow-gdpr-reg-user' => 1,
53 'gdpr-text-reg-user' => $gdpr_text,
54 'editor-reg-user' => 'html',
55 )
56 );
57 update_option( 'wpsc-gdpr-settings', $gdpr );
58 WPSC_Translations::remove( 'wpsc-gdpr', $gdpr['gdpr-text'] );
59 WPSC_Translations::remove( 'wpsc-gdpr-reg-user', $gdpr['gdpr-text-reg-user'] );
60 }
61
62 /**
63 * Settings user interface
64 *
65 * @return void
66 */
67 public static function load_settings_ui() {
68
69 if ( ! WPSC_Functions::is_site_admin() ) {
70 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
71 }
72 $settings = get_option( 'wpsc-gdpr-settings', array() );?>
73
74 <form action="#" onsubmit="return false;" class="wpsc-frm-ms-gdpr">
75 <div class="wpsc-dock-container">
76 <?php
77 printf(
78 /* translators: Click here to see the documentation */
79 esc_attr__( '%s to see the documentation!', 'supportcandy' ),
80 '<a href="https://supportcandy.net/docs/gdpr/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>'
81 );
82 ?>
83 </div>
84 <h3><?php esc_attr_e( 'Create ticket form', 'supportcandy' ); ?></h3>
85
86 <div class="wpsc-input-group">
87 <div class="label-container">
88 <label for=""><?php esc_attr_e( 'Enable', 'supportcandy' ); ?></label>
89 </div>
90 <select id="wpsc-allow-gdpr" name="allow-gdpr">
91 <option <?php selected( $settings['allow-gdpr'], 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
92 <option <?php selected( $settings['allow-gdpr'], 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
93 </select>
94 </div>
95 <div class="wpsc-input-group">
96 <div class="label-container">
97 <label for=""><?php esc_attr_e( 'Checkbox text', 'supportcandy' ); ?></label>
98 </div>
99 <div class="textarea-container ">
100 <div class="wpsc_tinymce_editor_btns">
101 <div class="inner-container">
102 <button class="visual wpsc-switch-editor wpsc-switch-editor-ct <?php echo esc_attr( $settings['editor'] ) == 'html' ? 'active' : ''; ?>" type="button" onclick="wpsc_get_tinymce(this, 'gdpr-text','gdpr_body');"><?php esc_attr_e( 'Visual', 'supportcandy' ); ?></button>
103 <button class="text wpsc-switch-editor wpsc-switch-editor-ct <?php echo esc_attr( $settings['editor'] ) == 'text' ? 'active' : ''; ?>" type="button" onclick="wpsc_get_textarea(this, 'gdpr-text')"><?php esc_attr_e( 'Text', 'supportcandy' ); ?></button>
104 </div>
105 </div>
106 <?php
107 $gdpr_text = $settings['gdpr-text'] ? WPSC_Translations::get( 'wpsc-gdpr', stripslashes( $settings['gdpr-text'] ) ) : stripslashes( $settings['gdpr-text'] );
108 ?>
109 <textarea name="gdpr-text" id="gdpr-text" class="wpsc_textarea"><?php echo wp_kses_post( $gdpr_text ); ?></textarea>
110 </div>
111 </div>
112
113 <hr>
114 <h3><?php esc_attr_e( 'Registration form', 'supportcandy' ); ?></h3>
115
116 <div class="wpsc-input-group">
117 <div class="label-container">
118 <label for=""><?php esc_attr_e( 'Enable', 'supportcandy' ); ?></label>
119 </div>
120 <select id="wpsc-allow-gdpr-reg-user" name="allow-gdpr-reg-user">
121 <option <?php selected( $settings['allow-gdpr-reg-user'], 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
122 <option <?php selected( $settings['allow-gdpr-reg-user'], 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
123 </select>
124 </div>
125 <div class="wpsc-input-group">
126 <div class="label-container">
127 <label for=""><?php esc_attr_e( 'Checkbox text', 'supportcandy' ); ?></label>
128 </div>
129 <div class="textarea-container ">
130 <div class="wpsc_tinymce_editor_btns">
131 <div class="inner-container">
132 <button class="visual wpsc-switch-editor wpsc-switch-editor-reg-user <?php echo esc_attr( $settings['editor-reg-user'] ) == 'html' ? 'active' : ''; ?>" type="button" onclick="wpsc_get_tinymce(this, 'gdpr-text-reg-user','gdpr_body');"><?php esc_attr_e( 'Visual', 'supportcandy' ); ?></button>
133 <button class="text wpsc-switch-editor wpsc-switch-editor-reg-user <?php echo esc_attr( $settings['editor-reg-user'] ) == 'text' ? 'active' : ''; ?>" type="button" onclick="wpsc_get_textarea(this, 'gdpr-text-reg-user')"><?php esc_attr_e( 'Text', 'supportcandy' ); ?></button>
134 </div>
135 </div>
136 <?php
137 $gdpr_text = $settings['gdpr-text-reg-user'] ? WPSC_Translations::get( 'wpsc-gdpr-reg-user', stripslashes( $settings['gdpr-text-reg-user'] ) ) : stripslashes( $settings['gdpr-text-reg-user'] );
138 ?>
139 <textarea name="gdpr-text-reg-user" id="gdpr-text-reg-user" class="wpsc_textarea"><?php echo wp_kses_post( $gdpr_text ); ?></textarea>
140 </div>
141 </div>
142 <hr>
143 <div class="wpsc-input-group">
144 <div class="label-container">
145 <label for=""><?php esc_attr_e( 'Personal data retention', 'supportcandy' ); ?></label>
146 </div>
147 <div class="divide-bar">
148 <input type="number" id="wpsc-personal-data-retention-time" name="personal-data-retention-time" value="<?php echo esc_attr( $settings['personal-data-retention-time'] ); ?>">
149 <select id="wpsc-personal-data-retention-unit" name="personal-data-retention-unit">
150 <option <?php selected( $settings['personal-data-retention-unit'], 'days' ); ?> value="days"><?php esc_attr_e( 'Day(s)', 'supportcandy' ); ?></option>
151 <option <?php selected( $settings['personal-data-retention-unit'], 'month' ); ?> value="month"><?php esc_attr_e( 'Month(s)', 'supportcandy' ); ?></option>
152 <option <?php selected( $settings['personal-data-retention-unit'], 'year' ); ?> value="year"><?php esc_attr_e( 'Year(s)', 'supportcandy' ); ?></option>
153 </select>
154 </div>
155 </div>
156 <?php do_action( 'wpsc_ms_gdpr' ); ?>
157 <input type="hidden" name="action" value="wpsc_set_ms_gdpr">
158 <input id="editor" type="hidden" name="editor" value="<?php echo esc_attr( $settings['editor'] ); ?>">
159 <input id="editor-reg-user" type="hidden" name="editor-reg-user" value="<?php echo esc_attr( $settings['editor-reg-user'] ); ?>">
160 <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_ms_gdpr' ) ); ?>">
161 </form>
162 <script>
163 <?php
164 if ( $settings['editor'] == 'html' ) {
165 ?>
166 jQuery('.wpsc-switch-editor-ct.visual').trigger('click');
167 <?php
168 }
169 if ( $settings['editor-reg-user'] == 'html' ) {
170 ?>
171 jQuery('.wpsc-switch-editor-reg-user.visual').trigger('click');
172 <?php
173 }
174 ?>
175
176 function wpsc_get_tinymce(el, selector, body_id){
177 jQuery(el).parent().find('.text').removeClass('active');
178 jQuery(el).addClass('active');
179 tinymce.remove('#'+selector);
180 tinymce.init({
181 selector:'#'+selector,
182 body_id: body_id,
183 menubar: false,
184 statusbar: false,
185 height : '200',
186 plugins: [
187 'lists link image directionality'
188 ],
189 image_advtab: true,
190 toolbar: 'bold italic underline blockquote | alignleft aligncenter alignright | bullist numlist | rtl | link image',
191 directionality: '<?php echo is_rtl() ? 'rtl' : 'ltr'; ?>',
192 branding: false,
193 autoresize_bottom_margin: 20,
194 browser_spellcheck : true,
195 relative_urls : false,
196 remove_script_host : false,
197 convert_urls : true,
198 setup: function (editor) {
199 }
200 });
201 if( selector == 'gdpr-text' ) {
202 jQuery('#editor').val('html');
203 }else{
204 jQuery('#editor-reg-user').val('html');
205 }
206 }
207
208 function wpsc_get_textarea(el, selector){
209 jQuery(el).parent().find('.visual').removeClass('active');
210 jQuery(el).addClass('active');
211 tinymce.remove('#'+selector);
212 if( selector == 'gdpr-text' ) {
213 jQuery('#editor').val('text');
214 }else{
215 jQuery('#editor-reg-user').val('text');
216 }
217 }
218 </script>
219 <div class="setting-footer-actions">
220 <button
221 class="wpsc-button normal primary margin-right"
222 onclick="wpsc_set_ms_gdpr(this);">
223 <?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button>
224 <button
225 class="wpsc-button normal secondary"
226 onclick="wpsc_reset_ms_gdpr(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_reset_ms_gdpr' ) ); ?>');">
227 <?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button>
228 </div>
229 <?php
230 wp_die();
231 }
232
233 /**
234 * Save settings
235 *
236 * @return void
237 */
238 public static function save_settings() {
239
240 if ( check_ajax_referer( 'wpsc_set_ms_gdpr', '_ajax_nonce', false ) != 1 ) {
241 wp_send_json_error( 'Unauthorised request!', 401 );
242 }
243
244 if ( ! WPSC_Functions::is_site_admin() ) {
245 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
246 }
247
248 $settings = apply_filters(
249 'wpsc_set_gdpr',
250 array(
251 'allow-gdpr' => isset( $_POST['allow-gdpr'] ) ? intval( $_POST['allow-gdpr'] ) : 1,
252 'gdpr-text' => isset( $_POST ) && isset( $_POST['gdpr-text'] ) ? wp_kses_post( wp_unslash( $_POST['gdpr-text'] ) ) : '',
253 'personal-data-retention-time' => isset( $_POST['personal-data-retention-time'] ) ? intval( $_POST['personal-data-retention-time'] ) : 0,
254 'personal-data-retention-unit' => isset( $_POST['personal-data-retention-unit'] ) ? sanitize_text_field( wp_unslash( $_POST['personal-data-retention-unit'] ) ) : 'days',
255 'editor' => isset( $_POST['editor'] ) ? sanitize_text_field( wp_unslash( $_POST['editor'] ) ) : 'html',
256 'allow-gdpr-reg-user' => isset( $_POST['allow-gdpr-reg-user'] ) ? intval( $_POST['allow-gdpr-reg-user'] ) : 1,
257 'gdpr-text-reg-user' => isset( $_POST ) && isset( $_POST['gdpr-text-reg-user'] ) ? wp_kses_post( wp_unslash( $_POST['gdpr-text-reg-user'] ) ) : '',
258 'editor-reg-user' => isset( $_POST['editor-reg-user'] ) ? sanitize_text_field( wp_unslash( $_POST['editor-reg-user'] ) ) : 'html',
259 )
260 );
261 update_option( 'wpsc-gdpr-settings', $settings );
262
263 // remove string translations.
264 WPSC_Translations::remove( 'wpsc-gdpr' );
265 WPSC_Translations::remove( 'wpsc-gdpr-reg-user' );
266
267 // add string translations.
268 WPSC_Translations::add( 'wpsc-gdpr', $settings['gdpr-text'] );
269 WPSC_Translations::add( 'wpsc-gdpr-reg-user', $settings['gdpr-text-reg-user'] );
270 wp_die();
271 }
272
273 /**
274 * Reset settings to default
275 *
276 * @return void
277 */
278 public static function reset_settings() {
279
280 if ( check_ajax_referer( 'wpsc_reset_ms_gdpr', '_ajax_nonce', false ) != 1 ) {
281 wp_send_json_error( 'Unauthorised request!', 401 );
282 }
283
284 if ( ! WPSC_Functions::is_site_admin() ) {
285 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
286 }
287 self::reset();
288 wp_die();
289 }
290
291 /**
292 * Print ticket form field
293 *
294 * @return void
295 */
296 public static function print_tff() {
297
298 $gdpr = get_option( 'wpsc-gdpr-settings' );
299 if ( intval( $gdpr['allow-gdpr'] ) === 1 ) {
300 ?>
301 <div class="wpsc-tff wpsc-gdpr wpsc-xs-12 wpsc-sm-12 wpsc-md-12 wpsc-lg-12 required wpsc-visible" data-cft="gdpr">
302 <div class="checkbox-container">
303 <?php $unique_id = uniqid( 'wpsc_' ); ?>
304 <input id="<?php echo esc_attr( $unique_id ); ?>" type="checkbox" value="1"/>
305 <?php
306 $name = WPSC_Translations::get( 'wpsc-gdpr', stripslashes( $gdpr['gdpr-text'] ) );
307 ?>
308 <label for="<?php echo esc_attr( $unique_id ); ?>"><?php echo wp_kses_post( $name ); ?></label>
309 </div>
310 </div>
311 <?php
312 }
313 }
314
315 /**
316 * Validate this type field in create ticket
317 *
318 * @return void
319 */
320 public static function js_validate_ticket_form() {
321 ?>
322
323 case 'gdpr':
324 var checkbox = customField.find('input:checked');
325 if (checkbox.length === 0) {
326 isValid = false;
327 alert(supportcandy.translations.req_gdpr);
328 }
329 break;
330 <?php
331 echo PHP_EOL;
332 }
333
334 /**
335 * Make tickets anonymous - gdpr setting - Personal data retention
336 *
337 * @return void
338 */
339 public static function personal_data_eraser() {
340
341 $settings = get_option( 'wpsc-gdpr-settings', array() );
342
343 // return if age.
344 if ( $settings['personal-data-retention-time'] === 0 ) {
345 return;
346 }
347
348 $tz = wp_timezone();
349 $today = new DateTime( 'now', $tz );
350
351 if ( $settings['personal-data-retention-unit'] == 'days' ) {
352 $today->sub( new DateInterval( 'P' . $settings['personal-data-retention-time'] . 'D' ) );
353 } elseif ( $settings['personal-data-retention-unit'] == 'month' ) {
354 $today->sub( new DateInterval( 'P' . $settings['personal-data-retention-time'] . 'M' ) );
355 } else {
356 $today->sub( new DateInterval( 'P' . $settings['personal-data-retention-time'] . 'Y' ) );
357 }
358
359 $filters = array(
360 'items_per_page' => 0,
361 'meta_query' => array(
362 'relation' => 'AND',
363 array(
364 'slug' => 'date_updated',
365 'compare' => '<',
366 'val' => $today->format( 'Y-m-d' ),
367 ),
368 array(
369 'slug' => 'customer',
370 'compare' => 'NOT IN',
371 'val' => array( 0 ),
372 ),
373 ),
374 );
375
376 $response = WPSC_Ticket::find( $filters );
377 $tickets = $response['results'];
378
379 foreach ( $tickets as $ticket ) {
380
381 self::anonymize_ticket( $ticket );
382 }
383 }
384
385 /**
386 * Anonymize ticket & customer data
387 *
388 * @param WPSC_Ticket $ticket - ticket object.
389 * @return void
390 */
391 public static function anonymize_ticket( $ticket ) {
392
393 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
394
395 if ( in_array( $cf->field, array( 'ticket', 'agentonly' ) ) && $cf->is_personal_info ) {
396 $val = $cf->type::$has_multiple_val ? array() : '';
397 $ticket->{$cf->slug} = $val;
398 }
399 }
400
401 $filters = array(
402 'meta_query' => array(
403 'relation' => 'AND',
404 array(
405 'slug' => 'customer',
406 'compare' => '=',
407 'val' => $ticket->customer->id,
408 ),
409 ),
410 );
411 $threads = WPSC_Thread::find( $filters )['results'];
412
413 $anonymous_customer = WPSC_Functions::anonymous_customer();
414 foreach ( $threads as $thread ) {
415 $thread->customer = $anonymous_customer;
416 $thread->save();
417 }
418
419 $ticket->customer = $anonymous_customer;
420 $ticket->save();
421
422 do_action( 'wpsc_after_anonymizing_ticket', $ticket );
423 }
424
425 /**
426 * Register privacy exporters
427 *
428 * @param array $exporters - privacy expoters.
429 * @return array
430 */
431 public static function wpsc_register_privacy_exporters( $exporters ) {
432
433 $exporters['wpsc_ticket_cust'] = array(
434 'exporter_friendly_name' => __( 'Ticket Customer', 'supportcandy' ),
435 'callback' => array( __CLASS__, 'wpsc_privacy_ticket_customer_exporter' ),
436 );
437
438 $exporters['wpsc_tickets'] = array(
439 'exporter_friendly_name' => __( 'Tickets', 'supportcandy' ),
440 'callback' => array( __CLASS__, 'wpsc_privacy_ticket_exporter' ),
441 );
442
443 return $exporters;
444 }
445
446 /**
447 * Add customer data to privacy exporter
448 *
449 * @param string $email_address - email address.
450 * @param integer $page - page numbers.
451 * @return array
452 */
453 public static function wpsc_privacy_ticket_customer_exporter( $email_address = '', $page = 1 ) {
454
455 $customer = WPSC_Customer::get_by_email( $email_address );
456 if ( ! $customer->id ) {
457 return;
458 }
459
460 $data = array(
461 array(
462 'name' => __( 'Name', 'supportcandy' ),
463 'value' => $customer->name,
464 ),
465 array(
466 'name' => __( 'Email', 'supportcandy' ),
467 'value' => $customer->email,
468 ),
469 );
470
471 $export_customer = array();
472 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
473
474 if ( $cf->field == 'customer' && $cf->is_personal_info && ! in_array( $cf->slug, WPSC_DF_Customer::$ignore_customer_info_cft ) && $customer->{$cf->slug} ) {
475
476 $data[] = array(
477 'name' => stripslashes( $cf->name ),
478 'value' => $cf->type::get_customer_field_val( $cf, $customer ),
479 );
480 }
481 }
482
483 $export_customer[] = array(
484 'group_id' => 'wpsc_ticket_cust',
485 'group_label' => __( 'Ticket Customer', 'supportcandy' ),
486 'item_id' => "wpsc_cust_id-{$customer->id}",
487 'data' => $data,
488 );
489
490 return array(
491 'data' => $export_customer,
492 'done' => true,
493 );
494 }
495
496 /**
497 * Add ticket data to privacy exporter
498 *
499 * @param string $email_address - email address.
500 * @param integer $page - page numbers.
501 * @return array
502 */
503 public static function wpsc_privacy_ticket_exporter( $email_address = '', $page = 1 ) {
504
505 $customer = WPSC_Customer::get_by_email( $email_address );
506 if ( ! $customer->id ) {
507 return;
508 }
509
510 $filters = array(
511 'items_per_page' => 0,
512 'meta_query' => array(
513 'relation' => 'AND',
514 array(
515 'slug' => 'customer',
516 'compare' => '=',
517 'val' => $customer->id,
518 ),
519 ),
520 );
521 $tickets = WPSC_Ticket::find( $filters )['results'];
522
523 $export_tickets = array();
524 foreach ( $tickets as $key => $ticket ) {
525
526 $data = array(
527 array(
528 'name' => __( 'Ticket ID', 'supportcandy' ),
529 'value' => $ticket->id,
530 ),
531 array(
532 'name' => __( 'Subject', 'supportcandy' ),
533 'value' => $ticket->subject,
534 ),
535 array(
536 'name' => __( 'IP Address', 'supportcandy' ),
537 'value' => $ticket->ip_address,
538 ),
539 array(
540 'name' => __( 'Browser', 'supportcandy' ),
541 'value' => $ticket->browser,
542 ),
543 array(
544 'name' => __( 'Operating System', 'supportcandy' ),
545 'value' => $ticket->os,
546 ),
547 );
548 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
549
550 if ( $cf->is_personal_info && in_array( $cf->field, array( 'ticket', 'agentonly' ) ) && ! $cf->type::$is_default && $ticket->{$cf->slug} ) {
551 $val = in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ? $cf->type::get_ticket_field_val( $cf, $ticket ) : $cf->type::get_customer_field_val( $cf, $ticket->customer );
552 $data[] = array(
553 'name' => stripslashes( $cf->name ),
554 'value' => $val,
555 );
556 }
557 }
558
559 $export_tickets[] = array(
560 'group_id' => 'wpsc_tickets',
561 'group_label' => __( 'User Tickets', 'supportcandy' ),
562 'item_id' => "wpsc_ticket_id-{$ticket->id}",
563 'data' => $data,
564 );
565 }
566
567 return array(
568 'data' => $export_tickets,
569 'done' => true,
570 );
571 }
572
573 /**
574 * Register privacy erasers
575 *
576 * @param array $erasers - rpivacy erasers.
577 * @return array
578 */
579 public static function wpsc_register_privacy_erasers( $erasers = array() ) {
580
581 $erasers[] = array(
582 'eraser_friendly_name' => __( 'Ticket Records', 'supportcandy' ),
583 'callback' => array( __CLASS__, 'wpsc_privacy_customer_erasers' ),
584 );
585
586 return $erasers;
587 }
588
589 /**
590 * Erase customer ticket data
591 *
592 * @param string $email_address - email address.
593 * @param integer $page - page numbers.
594 * @return array
595 */
596 public static function wpsc_privacy_customer_erasers( $email_address, $page = 1 ) {
597
598 $customer = WPSC_Customer::get_by_email( $email_address );
599 if ( ! $customer->id ) {
600 return;
601 }
602
603 $filters = array(
604 'items_per_page' => 0,
605 'meta_query' => array(
606 'relation' => 'AND',
607 array(
608 'slug' => 'customer',
609 'compare' => '=',
610 'val' => $customer->id,
611 ),
612 ),
613 );
614 $tickets = WPSC_Ticket::find( $filters )['results'];
615
616 foreach ( $tickets as $ticket ) {
617
618 self::anonymize_ticket( $ticket );
619 }
620
621 WPSC_Customer::destroy( $customer );
622
623 /* translators: %s: email address */
624 $message = sprintf( __( 'Tickets of customer having email %s has been anonymized.', 'supportcandy' ), $email_address );
625 return array(
626 'items_removed' => true,
627 'items_retained' => false,
628 'messages' => array( $message ),
629 'done' => true,
630 );
631 }
632 }
633 endif;
634
635 WPSC_MS_GDPR::init();
636