PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.1
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.1
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.4.1, at includes/admin/settings/miscellaneous-settings/class-wpsc-ms-gdpr.php

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