| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $wpdb, $current_user, $wpscfunction; |
| 7 |
|
| 8 |
$params = $request->get_params(); |
| 9 |
|
| 10 |
//Get Ticket Id |
| 11 |
$ticket_id = isset( $params['id'] ) ? sanitize_text_field($params['id']) : 0; |
| 12 |
|
| 13 |
$response = array(); |
| 14 |
|
| 15 |
//Get Reply body |
| 16 |
$reply_body = isset($params['reply_body']) ? wp_kses_post(htmlspecialchars_decode($params['reply_body'], ENT_QUOTES)) : ''; |
| 17 |
//$reply_body = str_replace(' ', ' ', $reply_body); |
| 18 |
|
| 19 |
// Attachments for reply description |
| 20 |
$desc_attachment = isset($params['attachments']) && trim($params['attachments']) != '' ? json_decode($params['attachments']) : new stdClass(); |
| 21 |
$description_attachment = isset($desc_attachment->attachments) ? $wpscfunction->sanitize_array($desc_attachment->attachments) : array(); |
| 22 |
$attachments = array(); |
| 23 |
foreach ($description_attachment as $key => $value) { |
| 24 |
$attachment_id = intval($value); |
| 25 |
$attachments[] = $attachment_id; |
| 26 |
update_term_meta ($attachment_id, 'active', '1'); |
| 27 |
} |
| 28 |
|
| 29 |
// Prepare arguments |
| 30 |
$args = array( |
| 31 |
'ticket_id' => $ticket_id, |
| 32 |
'reply_body' => $wpscfunction->replace_macro($reply_body,$ticket_id), |
| 33 |
'attachments' => $attachments, |
| 34 |
'customer_name' => $current_user->display_name, |
| 35 |
'customer_email' => $current_user->user_email, |
| 36 |
'thread_type' => 'reply' |
| 37 |
); |
| 38 |
|
| 39 |
$args = apply_filters( 'wpsc_thread_args', $args ); |
| 40 |
|
| 41 |
if ($reply_body) { |
| 42 |
|
| 43 |
$thread_id = $wpscfunction->submit_ticket_thread($args); |
| 44 |
|
| 45 |
do_action( 'wpsc_after_submit_reply', $thread_id, $ticket_id ); |
| 46 |
|
| 47 |
$response = array( |
| 48 |
'status' => 200, |
| 49 |
'thread_id' => $thread_id |
| 50 |
); |
| 51 |
|
| 52 |
} else { |
| 53 |
|
| 54 |
$response = new WP_Error( |
| 55 |
'operation_failed', |
| 56 |
'Reply not submitted.', |
| 57 |
array( |
| 58 |
'status' => 403, |
| 59 |
) |
| 60 |
); |
| 61 |
|
| 62 |
} |
| 63 |
|