PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.3
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.3
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 / rest-api / class-wpsc-rest-individual-ticket.php

class-wpsc-rest-individual-ticket.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.3, at includes/rest-api/class-wpsc-rest-individual-ticket.php

697 lines 20.8 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_REST_Individual_Ticket' ) ) :
7
8 final class WPSC_REST_Individual_Ticket {
9
10 /**
11 * Array of ticket slugs which we do not want to expose to REST API
12 *
13 * @var array
14 */
15 public static $prevent_data = array();
16
17 /**
18 * Initialize this class
19 *
20 * @return void
21 */
22 public static function init() {
23
24 add_action( 'wpsc_rest_load_ticket_prevent_data', array( __CLASS__, 'load_prevent_data' ) );
25 }
26
27 /**
28 * Load prevent data
29 *
30 * @return void
31 */
32 public static function load_prevent_data() {
33
34 $current_user = WPSC_Current_User::$current_user;
35 $data = ! $current_user->is_agent ? array( 'ip_address', 'source', 'browser', 'os', 'user_type' ) : array();
36 self::$prevent_data = apply_filters( 'wpsc_rest_prevent_ticket_data', $data );
37 }
38
39 /**
40 * Create new ticket
41 *
42 * @param WP_REST_Request $request - request object.
43 * @return WP_Error|WP_REST_Response
44 */
45 public static function create( $request ) {
46
47 $current_user = WPSC_Current_User::$current_user;
48 $gs = get_option( 'wpsc-gs-general' );
49 $advanced = get_option( 'wpsc-ms-advanced-settings' );
50
51 if ( ! (
52 ( ! $current_user->user->ID && in_array( 'guest', $gs['allow-create-ticket'] ) ) ||
53 ( $current_user->is_agent && in_array( $current_user->agent->role, $gs['allow-create-ticket'] ) ) ||
54 ( ! $current_user->is_agent && $current_user->user->ID && in_array( 'registered-user', $gs['allow-create-ticket'] ) )
55 ) ) {
56 return new WP_REST_Response( new WP_Error( 'unauthorized', 'You are not authorized to create ticket!' ), 401 );
57 }
58
59 // group by custom field type.
60 $cfs = array();
61 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
62 $cfs[ $cf->type::$slug ][] = $cf;
63 }
64
65 // collect all data to create ticket.
66 $data = apply_filters(
67 'wpsc_rest_create_ticket',
68 array( 'errors' => new WP_Error() ),
69 $request,
70 $cfs
71 );
72
73 // check whether there are any errors.
74 if ( $data['errors']->has_errors() ) {
75 return new WP_REST_Response( $data['errors'], 400 );
76 } else {
77 unset( $data['errors'] );
78 }
79
80 // Seperate description from $data.
81 $description = $data['description'];
82 unset( $data['description'] );
83
84 // Seperate description attachments from $data.
85 $description_attachments = $data['description_attachments'];
86 unset( $data['description_attachments'] );
87
88 $data['last_reply_on'] = ( new DateTime() )->format( 'Y-m-d H:i:s' );
89
90 // insert ticket data.
91 $ticket = WPSC_Ticket::insert( $data );
92
93 if ( ! $ticket ) {
94 return new WP_REST_Response( new WP_Error( 'something_wrong', 'Something went wrong!' ), 400 );
95 }
96
97 $thread_customer = $current_user->is_agent && $current_user->customer->id != $ticket->customer->id && $advanced['raised-by-user'] == 'agent' ? $current_user->customer : $ticket->customer;
98 $ticket->last_reply_by = $thread_customer->id;
99 $ticket->last_reply_source = 'rest-api';
100 $ticket->save();
101
102 // replace macros only when current user is an agent.
103 $description = $current_user->is_agent ? WPSC_Macros::replace( $description, $ticket ) : $description;
104
105 // set signature if agent.
106 $signature = $current_user->is_agent && $current_user->customer->email == $ticket->customer->email ? $current_user->agent->get_signature() : '';
107 if ( $signature ) {
108 $description .= $signature;
109 }
110
111 // Create report thread.
112 $thread = WPSC_Thread::insert(
113 array(
114 'ticket' => $ticket->id,
115 'customer' => $thread_customer->id,
116 'type' => 'report',
117 'body' => $description,
118 'attachments' => $description_attachments,
119 'ip_address' => $ticket->ip_address,
120 'source' => $ticket->source,
121 'os' => $ticket->os,
122 'browser' => $ticket->browser,
123 )
124 );
125
126 do_action( 'wpsc_create_new_ticket', $ticket );
127
128 WPSC_Email_Notifications::send_background_emails();
129
130 $request = new WP_REST_Request( 'GET', '/supportcandy/v2/tickets/' . $ticket->id );
131 return rest_do_request( $request );
132 }
133
134 /**
135 * Get individual ticket
136 *
137 * @param WP_REST_Request $request - request object.
138 * @return WP_Error|WP_REST_Response
139 */
140 public static function get( $request ) {
141
142 $current_user = WPSC_Current_User::$current_user;
143
144 // triggers loading of prevent ticket data property.
145 do_action( 'wpsc_rest_load_ticket_prevent_data' );
146
147 $ticket = new WPSC_Ticket( $request->get_param( 'id' ) );
148 if ( ! $ticket->id ) {
149 return new WP_REST_Response( new WP_Error( 'unauthorized', 'You are not authorized!' ), 401 );
150 }
151
152 WPSC_Individual_Ticket::$ticket = $ticket;
153 if ( ! (
154 ( $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'view' ) ) ||
155 WPSC_Individual_Ticket::is_customer()
156 ) ) {
157 return new WP_REST_Response( new WP_Error( 'unauthorized', 'You are not authorized!' ), 401 );
158 }
159
160 $data = self::modify_response( $ticket->to_array() );
161 return new WP_REST_Response( $data, 200 );
162 }
163
164 /**
165 * Update/modify the ticket
166 *
167 * @param WP_REST_Request $request - request object.
168 * @return WP_Error|WP_REST_Response
169 */
170 public static function update( $request ) {
171
172 $current_user = WPSC_Current_User::$current_user;
173
174 $ticket = new WPSC_Ticket( $request->get_param( 'id' ) );
175 if ( ! $ticket->id || ! $ticket->is_active ) {
176 return new WP_REST_Response( new WP_Error( 'unauthorized', 'You are not authorized!' ), 401 );
177 }
178
179 // ticket object clone to compare.
180 $ticket_clone = clone $ticket;
181 WPSC_Individual_Ticket::$ticket = $ticket;
182 $agentonly_fields = array();
183 foreach ( $request->get_params() as $slug => $val ) {
184
185 if ( in_array( $slug, array( 'id', 'description', 'description_attachments' ) ) ) {
186 continue;
187 }
188
189 $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
190 if ( ! $cf || ! in_array( $cf->field, array( 'ticket' ) ) ) {
191
192 if ( $cf || in_array( $cf->field, array( 'agentonly' ) ) ) {
193 $agentonly_fields[ $slug ] = $val;
194 }
195 continue;
196 }
197
198 // subject.
199 if ( $slug == 'subject' && $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'ctf' ) ) {
200
201 $prev = $ticket->subject;
202 $new = sanitize_text_field( $val );
203 if ( ! $new || $prev == $new ) {
204 continue;
205 }
206
207 $ticket->subject = $new;
208 do_action( 'wpsc_change_ticket_subject', $ticket, $prev, $new, $current_user->customer->id );
209 }
210
211 // status.
212 if ( $slug == 'status' && $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'cs' ) ) {
213
214 $status = new WPSC_Status( intval( $val ) );
215 if ( ! $status->id || $ticket->status == $status ) {
216 continue;
217 }
218
219 WPSC_Individual_Ticket::change_status( $ticket->status->id, $status->id, $current_user->customer->id );
220 }
221
222 // priority.
223 if ( $slug == 'priority' && $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'cs' ) ) {
224
225 $priority = new WPSC_Priority( intval( $val ) );
226 if ( ! $priority->id || $ticket->priority == $priority ) {
227 continue;
228 }
229
230 WPSC_Individual_Ticket::change_priority( $ticket->priority->id, $priority->id, $current_user->customer->id );
231 }
232
233 // category.
234 if ( $slug == 'category' && $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'cs' ) ) {
235
236 $category = new WPSC_Category( intval( $val ) );
237 if ( ! $category->id || $ticket->category == $category ) {
238 continue;
239 }
240
241 WPSC_Individual_Ticket::change_category( $ticket->category->id, $category->id, $current_user->customer->id );
242 }
243
244 // customer.
245 if ( $slug == 'customer' && $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'crb' ) ) {
246
247 $customer = new WPSC_Customer( intval( $val ) );
248 if ( ! $customer->id || $ticket->customer == $customer ) {
249 continue;
250 }
251
252 WPSC_Individual_Ticket::change_raised_by( $ticket->customer, $customer, $current_user->customer->id );
253 }
254
255 // assignee.
256 if ( $slug == 'assigned_agent' && $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'aa' ) ) {
257
258 $new = array_unique(
259 array_filter(
260 array_map(
261 function ( $id ) {
262 $agent = new WPSC_Agent( intval( $id ) );
263 return $agent->id ? $agent->id : false;
264 },
265 explode( ',', sanitize_text_field( $val ) )
266 )
267 )
268 );
269
270 $prev = array_unique(
271 array_filter(
272 array_map(
273 fn( $agent ) => $agent->id,
274 $ticket->assigned_agent
275 )
276 )
277 );
278
279 if ( ! $new || ! ( array_diff( $prev, $new ) || array_diff( $new, $prev ) ) ) {
280 continue;
281 }
282
283 $new = array_map(
284 fn( $id ) => new WPSC_Agent( $id ),
285 $new
286 );
287
288 WPSC_Individual_Ticket::change_assignee( $ticket->assigned_agent, $new, $current_user->customer->id );
289 }
290
291 // additional recipients.
292 if (
293 $slug == 'add_recipients' &&
294 (
295 ( $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'ar' ) ) ||
296 ( ! $current_user->is_agent && $ticket->customer->id == $current_user->customer->id )
297 )
298 ) {
299
300 $recipients = array_unique( array_filter( array_map( 'sanitize_email', explode( ',', $val ) ) ) );
301 $prev = $ticket->add_recipients;
302 if ( ! $recipients || ! ( array_diff( $prev, $recipients ) || array_diff( $recipients, $prev ) ) ) {
303 continue;
304 }
305
306 $ticket->add_recipients = $recipients;
307 do_action( 'wpsc_change_ticket_add_recipients', $ticket, $prev, $recipients, $current_user->customer->id );
308 }
309
310 // ticket fields.
311 if (
312 class_exists( $cf->type ) &&
313 $current_user->is_agent &&
314 WPSC_Individual_Ticket::has_ticket_cap( 'ctf' ) &&
315 ! $cf->type::$is_default &&
316 ! in_array( $cf->type::$slug, WPSC_ITW_Ticket_Fields::$ignore_cft )
317 ) {
318 $cf->type::set_rest_edit_ticket_cf( $ticket, $cf, $val );
319 }
320
321 do_action( 'wpsc_rest_update_ticket_field', $ticket, $slug, $val, $cf );
322 }
323 // save the changes.
324 if ( $ticket != $ticket_clone ) {
325 $ticket->date_updated = new DateTime();
326 $ticket->save();
327 do_action( 'wpsc_change_ticket_fields', $ticket_clone, $ticket );
328 }
329
330 // ticket object clone to compare. Seperate loop to avoid duplicate logs and actions.
331 $ticket_clone = clone $ticket;
332 WPSC_Individual_Ticket::$ticket = $ticket;
333 foreach ( $agentonly_fields as $slug => $val ) {
334
335 if ( in_array( $slug, array( 'id', 'description', 'description_attachments' ) ) ) {
336 continue;
337 }
338
339 $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
340 if ( ! $cf || ! in_array( $cf->field, array( 'agentonly' ) ) ) {
341 continue;
342 }
343
344 if (
345 // agentonly fields.
346 class_exists( $cf->type ) &&
347 $current_user->is_agent &&
348 WPSC_Individual_Ticket::has_ticket_cap( 'caof' ) &&
349 ! $cf->type::$is_default &&
350 ! in_array( $cf->type::$slug, WPSC_ITW_Agentonly_Fields::$ignore_cft )
351 ) {
352
353 $cf->type::set_rest_edit_ticket_cf( $ticket, $cf, $val );
354 }
355 }
356 // save the changes.
357 if ( $ticket != $ticket_clone ) {
358 $ticket->date_updated = new DateTime();
359 $ticket->save();
360 do_action( 'wpsc_change_agentonly_fields', $ticket_clone, $ticket );
361 }
362
363 $request = new WP_REST_Request( 'GET', '/supportcandy/v2/tickets/' . $ticket->id );
364 return rest_do_request( $request );
365 }
366
367 /**
368 * Delete the ticket
369 *
370 * @param WP_REST_Request $request - request object.
371 * @return WP_Error|WP_REST_Response
372 */
373 public static function delete( $request ) {
374
375 $current_user = WPSC_Current_User::$current_user;
376 if ( ! $current_user->is_agent ) {
377 return new WP_REST_Response( new WP_Error( 'unauthorized', 'You are not authorized to delete ticket!' ), 401 );
378 }
379
380 $ticket = new WPSC_Ticket( $request->get_param( 'id' ) );
381 if ( ! $ticket->id ) {
382 return new WP_REST_Response( new WP_Error( 'bad_request', 'Bad request!' ), 400 );
383 }
384
385 WPSC_Individual_Ticket::$ticket = $ticket;
386 if ( ! WPSC_Individual_Ticket::$ticket->is_active || ! WPSC_Individual_Ticket::has_ticket_cap( 'dtt' ) ) {
387 return new WP_REST_Response( new WP_Error( 'unauthorized', 'You are not authorized to delete this ticket!' ), 401 );
388 }
389
390 WPSC_Individual_Ticket::delete_archive_ticket();
391 return new WP_REST_Response( array( 'success' => true ), 200 );
392 }
393
394 /**
395 * Get ticket threads
396 *
397 * @param WP_REST_Request $request - request object.
398 * @return WP_Error|WP_REST_Response
399 */
400 public static function get_threads( $request ) {
401
402 $current_user = WPSC_Current_User::$current_user;
403
404 $ticket = new WPSC_Ticket( $request->get_param( 'id' ) );
405 if ( ! $ticket->id || ! $ticket->is_active ) {
406 return new WP_REST_Response( new WP_Error( 'unauthorized', 'You are not authorized!' ), 401 );
407 }
408
409 WPSC_Individual_Ticket::$ticket = $ticket;
410 if ( ! (
411 ( $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'view' ) ) ||
412 ( WPSC_Individual_Ticket::is_customer() )
413 ) ) {
414 return new WP_REST_Response( new WP_Error( 'unauthorized', 'You are not authorized!' ), 401 );
415 }
416
417 $filters = array(
418 'page_no' => $request->get_param( 'page' ),
419 'items_per_page' => $request->get_param( 'per_page' ),
420 'order' => $request->get_param( 'order' ),
421 'meta_query' => array(
422 'relation' => 'AND',
423 array(
424 'slug' => 'ticket',
425 'compare' => '=',
426 'val' => $ticket->id,
427 ),
428 array(
429 'slug' => 'is_active',
430 'compare' => '=',
431 'val' => 1,
432 ),
433 ),
434 );
435
436 $type = array(
437 'slug' => 'type',
438 'compare' => 'IN',
439 'val' => array( 'report', 'reply' ),
440 );
441
442 // private note.
443 if ( $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'pn' ) ) {
444 $type['val'][] = 'note';
445 }
446
447 // logs.
448 if ( $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'vl' ) ) {
449 $type['val'][] = 'log';
450 }
451
452 $filters['meta_query'][] = $type;
453 $response = WPSC_Thread::find( $filters, false );
454
455 return new WP_REST_Response( self::modify_thread_response( $response, $ticket, $current_user ), 200 );
456 }
457
458 /**
459 * Add new thread
460 *
461 * @param WP_REST_Request $request - request object.
462 * @return WP_Error|WP_REST_Response
463 */
464 public static function add_new_thread( $request ) {
465
466 $current_user = WPSC_Current_User::$current_user;
467
468 $ticket = new WPSC_Ticket( $request->get_param( 'id' ) );
469 if ( ! $ticket->id || ! $ticket->is_active ) {
470 return new WP_REST_Response( new WP_Error( 'unauthorized', 'You are not authorized!' ), 401 );
471 }
472
473 WPSC_Individual_Ticket::$ticket = $ticket;
474 $type = $request->get_param( 'type' );
475 $body = $request->get_param( 'body' );
476 $source = $request->get_param( 'source' );
477
478 $attachments = $request->get_param( 'attachments' );
479 $validated_attachments = array();
480 foreach ( $attachments as $id ) {
481
482 $attachment = new WPSC_Attachment( $id );
483 if ( ! $attachment->id ||
484 ( $attachment->ticket_id && $attachment->is_active ) ) {
485 continue;
486 }
487
488 $validated_attachments[] = $id;
489 }
490 $attachments = $validated_attachments;
491
492 // Set reply profile.
493 WPSC_Individual_Ticket::$reply_profile = 'agent';
494 if ( WPSC_Individual_Ticket::is_customer() ) {
495 WPSC_Individual_Ticket::$reply_profile = 'customer';
496 }
497
498 if ( ! (
499 ( $current_user->is_agent && $type == 'reply' && WPSC_Individual_Ticket::has_ticket_cap( 'reply' ) ) ||
500 ( $current_user->is_agent && $type == 'note' && WPSC_Individual_Ticket::has_ticket_cap( 'pn' ) ) ||
501 ( WPSC_Individual_Ticket::is_customer() && $type == 'reply' )
502 ) ) {
503 return new WP_REST_Response( new WP_Error( 'unauthorized', 'You are not authorized!' ), 401 );
504 }
505
506 // submit thread.
507 $thread = WPSC_Thread::insert(
508 array(
509 'ticket' => $ticket->id,
510 'customer' => $current_user->customer->id,
511 'type' => $type,
512 'body' => $body,
513 'attachments' => implode( '|', $attachments ),
514 'ip_address' => WPSC_DF_IP_Address::get_current_user_ip(),
515 'source' => $source,
516 )
517 );
518
519 // save attachments.
520 foreach ( $attachments as $id ) {
521
522 $attachment = new WPSC_Attachment( $id );
523 $attachment->is_active = 1;
524 $attachment->source = $type;
525 $attachment->source_id = $thread->id;
526 $attachment->ticket_id = $ticket->id;
527 $attachment->save();
528 }
529
530 $ticket->date_updated = new DateTime();
531 $ticket->last_reply_on = new DateTime();
532 $ticket->last_reply_by = $current_user->customer->id;
533 $ticket->last_reply_source = $source;
534 $ticket->save();
535
536 if ( $type == 'reply' ) {
537 do_action( 'wpsc_post_reply', $thread );
538 } else {
539 do_action( 'wpsc_submit_note', $thread );
540 }
541
542 WPSC_Email_Notifications::send_background_emails();
543
544 $response = self::modify_thread_response( array( 'results' => array( $thread->to_array() ) ), $ticket, $current_user );
545 return new WP_REST_Response( $response['results'][0], 200 );
546 }
547
548 /**
549 * Modify ticket response data appropreate for client side
550 *
551 * @param array $ticket - ticket response array.
552 * @return array
553 */
554 public static function modify_response( $ticket ) {
555
556 $current_user = WPSC_Current_User::$current_user;
557
558 foreach ( $ticket as $slug => $value ) {
559
560 // remove prevent ticket data.
561 if ( in_array( $slug, self::$prevent_data ) ) {
562 unset( $ticket[ $slug ] );
563 continue;
564 }
565
566 $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
567
568 // ignore if no custom field type class is loaded.
569 if ( ! $cf ) {
570 unset( $ticket[ $slug ] );
571 continue;
572 }
573
574 // ignore agentonly fields for non-agent.
575 if ( ! $current_user->is_agent && $cf->field == 'agentonly' ) {
576 unset( $ticket[ $slug ] );
577 continue;
578 }
579
580 // convert has multiple values to array.
581 if ( WPSC_Ticket::$schema[ $slug ]['has_multiple_val'] ) {
582 if ( $value ) {
583 $ticket[ $slug ] = array_filter(
584 array_map(
585 fn( $val ) => is_numeric( $val ) ? intval( $val ) : $val,
586 explode( '|', $value )
587 )
588 );
589 } else {
590 $ticket[ $slug ] = array();
591 }
592 continue;
593 }
594
595 // empty date value.
596 if ( $value == '0000-00-00 00:00:00' ) {
597 $ticket[ $slug ] = '';
598 }
599
600 // cast numeric fields into integer.
601 if ( is_numeric( $value ) ) {
602 $ticket[ $slug ] = intval( $value );
603 }
604 }
605
606 return apply_filters( 'wpsc_rest_modify_ticket_response', $ticket );
607 }
608
609 /**
610 * Modify thread response
611 *
612 * @param array $response - response array.
613 * @param WPSC_Ticket $ticket - ticket object.
614 * @param WPSC_Current_User $current_user - current user object.
615 * @return array
616 */
617 public static function modify_thread_response( $response, $ticket, $current_user ) {
618
619 if ( $response['results'] ) {
620
621 $log_items = apply_filters(
622 'wpsc_rest_allowed_thread_log_items',
623 array( 'id', 'customer', 'type', 'body', 'date_created' )
624 );
625
626 $reply_items = apply_filters(
627 'wpsc_rest_allowed_thread_reply_items',
628 array( 'id', 'customer', 'type', 'body', 'attachments', 'seen', 'date_created' )
629 );
630
631 $response['results'] = array_map(
632 function ( $thread ) use ( $log_items, $reply_items ) {
633 $items = $thread['type'] == 'log' ? $log_items : $reply_items;
634 $temp = array();
635 foreach ( $items as $item ) {
636 switch ( $item ) {
637 case 'body':
638 if ( $thread['type'] == 'log' ) {
639 $body = json_decode( $thread[ $item ], true );
640 // Handle 'prev' field.
641 if ( isset( $body['prev'] ) ) {
642 if ( is_array( $body['prev'] ) ) {
643 $body['prev'] = implode( ',', $body['prev'] );
644 }
645 if ( is_string( $body['prev'] ) && strpos( $body['prev'], '|' ) !== false ) {
646 $body['prev'] = str_replace( '|', ',', $body['prev'] );
647 }
648 }
649 // Handle 'new' field.
650 if ( isset( $body['new'] ) ) {
651 if ( is_array( $body['new'] ) ) {
652 $body['new'] = implode( ',', $body['new'] );
653 }
654 if ( is_string( $body['new'] ) && strpos( $body['new'], '|' ) !== false ) {
655 $body['new'] = str_replace( '|', ',', $body['new'] );
656 }
657 }
658 $temp[ $item ] = $body;
659 } else {
660 $temp[ $item ] = $thread[ $item ];
661 }
662 break;
663 case 'attachments':
664 $temp[ $item ] = str_replace( '|', ',', $thread[ $item ] );
665 break;
666 default:
667 $temp[ $item ] = $thread[ $item ];
668 }
669 }
670 return $temp;
671 },
672 $response['results']
673 );
674 }
675
676 return $response;
677 }
678
679 /**
680 * Validate id
681 *
682 * @param string $param - parameter value.
683 * @param WP_REST_Request $request - request object.
684 * @param string $key - filter key.
685 * @return boolean
686 */
687 public static function validate_id( $param, $request, $key ) {
688
689 $error = new WP_Error( 'invalid_id', 'Invalid ticket id', array( 'status' => 400 ) );
690 $ticket = new WPSC_Ticket( $param );
691 return $ticket->id ? true : $error;
692 }
693 }
694 endif;
695
696 WPSC_REST_Individual_Ticket::init();
697