PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 2.3.1
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v2.3.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 / actions / en_submit_reply.php

en_submit_reply.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 2.3.1, at includes/actions/en_submit_reply.php

174 lines 5.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 global $wpscfunction, $current_user,$wpdb;
7
8 $from_name = get_option('wpsc_en_from_name','');
9 $from_email = get_option('wpsc_en_from_email','');
10 $reply_to = get_option('wpsc_en_reply_to','');
11 $ignore_emails = get_option('wpsc_en_ignore_emails','');
12
13 $wpsc_email_sending_method = get_option('wpsc_email_sending_method') ;
14
15 if ( !$from_name || !$from_email ) {
16 return;
17 }
18
19 $email_templates = get_terms([
20 'taxonomy' => 'wpsc_en',
21 'hide_empty' => false,
22 'orderby' => 'ID',
23 'order' => 'ASC',
24 'meta_query' => array(
25 'relation' => 'AND',
26 array(
27 'key' => 'type',
28 'value' => 'ticket_reply',
29 'compare' => '='
30 ),
31 ),
32 ]);
33
34 $email_subject = get_option('wpsc_email_notification_subject');
35 $email_body = get_option('wpsc_email_notification_body');
36
37 foreach ($email_templates as $email) :
38
39 $conditions = get_term_meta($email->term_id,'conditions',true);
40 if( $wpscfunction->check_ticket_conditions($conditions,$ticket_id) ) :
41
42 $subject = $wpscfunction->replace_macro($email_subject['email_subject_' . $email->term_id], $ticket_id);
43 $subject = '['.get_option('wpsc_ticket_alice','').$ticket_id.'] '.stripslashes($subject);
44 $body = $wpscfunction->replace_macro(stripslashes($email_body['email_body_' . $email->term_id]), $ticket_id);
45 $recipients = get_term_meta($email->term_id,'recipients',true);
46 $extra_recipients = get_term_meta($email->term_id,'extra_recipients',true);
47
48 $email_addresses = array();
49 foreach ($recipients as $recipient) {
50 if(is_numeric($recipient)){
51 $agents = get_terms([
52 'taxonomy' => 'wpsc_agents',
53 'hide_empty' => false,
54 'meta_query' => array(
55 'relation' => 'AND',
56 array(
57 'key' => 'role',
58 'value' => $recipient,
59 'compare' => '='
60 ),
61 ),
62 ]);
63 foreach ($agents as $agent) {
64 $user_id = get_term_meta($agent->term_id,'user_id',true);
65 if($user_id){
66 $user = get_user_by('id',$user_id);
67 $email_addresses[] = $user->user_email;
68 }
69 }
70 } else {
71 switch ($recipient) {
72 case 'customer':
73 $customer_email = $wpscfunction->get_ticket_fields($ticket_id,'customer_email');
74 $email_addresses[] = $customer_email;
75 break;
76 case 'assigned_agent':
77 $email_addresses = array_merge($email_addresses,$wpscfunction->get_assigned_agent_emails($ticket_id));
78 break;
79 case 'previously_assigned_agent':
80 $email_addresses = array_merge($email_addresses,$wpscfunction->get_previously_assigned_agents($ticket_id));
81 break;
82 case 'extra_ticket_users' :
83 $extra_users = $wpscfunction->get_ticket_meta($ticket_id,'extra_ticket_users');
84 $email_addresses = array_merge($email_addresses, $extra_users);
85 break;
86 }
87 }
88 }
89 if(isset($extra_recipients[0]) && $extra_recipients[0] ) {
90 $email_addresses = array_merge($email_addresses,$extra_recipients);
91 }
92
93 $bcc = isset($_POST['reply_bcc']) ? trim($_POST['reply_bcc']) : '';
94 if ($bcc) {
95 $bcc = array_filter(array_map('sanitize_email', explode(',', $bcc)));
96 $email_addresses = array_merge($email_addresses, $bcc);
97 }
98
99 $last_reply = $wpscfunction->get_last_reply($ticket_id);
100 if(in_array('current_user', $recipients)){
101 $email_addresses[] = $last_reply['user_email'];
102 }else{
103 $email_addresses = array_diff($email_addresses,array($last_reply['user_email']));
104 }
105 $email_addresses = apply_filters('wpsc_en_submit_reply_email_addresses',$email_addresses,$email,$thread_id,$ticket_id);
106 $email_addresses = array_values($email_addresses);
107
108 if ($ignore_emails) {
109 $ignore_emails = array_map('trim', $ignore_emails);
110 $email_addresses = array_map('trim', $email_addresses);
111 foreach ($ignore_emails as $ignore_email) {
112 foreach($email_addresses as $index => $email){
113 if(fnmatch($ignore_email, $email)){
114 unset($email_addresses[$index]);
115 }
116 }
117 }
118 }
119 $email_addresses = array_unique($email_addresses);
120 $email_addresses = array_values($email_addresses);
121
122 $to = isset($email_addresses[0])? $email_addresses[0] : '';
123 if($to){
124 unset($email_addresses[0]);
125 } else {
126 continue; // no email address found to send. So go to next foreach iteration.
127 }
128
129 // Customization filter
130 $from_email = apply_filters('wpsc_reply_from_email_headers',$from_email,$ticket_id);
131 $reply_to = apply_filters('wpsc_reply_replyto_headers',$reply_to,$ticket_id);
132
133 $bcc = implode(',',$email_addresses);
134
135 $to = apply_filters('wpsc_submit_reply_to_email',$to,$email_addresses,$ticket_id);
136 $bcc = apply_filters('wpsc_submit_reply_bcc_emails',$bcc,$email_addresses,$ticket_id);
137
138 $args = array(
139 'ticket_id' => $ticket_id,
140 'from_email' => $from_email,
141 'reply_to' => $reply_to,
142 'email_subject' => $subject,
143 'email_body' => $body,
144 'to_email' => $to,
145 'bcc_email' => $bcc,
146 'date_created' => date("Y-m-d H:i:s"),
147 'mail_status' => 0,
148 'email_type' => 'submit_reply',
149
150 );
151 if($wpsc_email_sending_method){
152
153 $wpdb->insert( $wpdb->prefix . 'wpsc_email_notification',$args);
154
155 }else{
156
157 $headers = "From: {$from_name} <{$from_email}>\r\n";
158 $headers .= "Reply-To: {$reply_to}\r\n";
159 $email_addresses = explode(',',$bcc);
160 foreach ($email_addresses as $email_address) {
161 if(strlen($email_address)) $headers .= "BCC: {$email_address}\r\n";
162 }
163
164 $headers .= "Content-Type: text/html; charset=utf-8\r\n";
165
166 wp_mail($to, $subject, $body, $headers);
167 }
168
169 do_action('wpsc_after_submit_reply_mail',$ticket_id,$args);
170
171 endif;
172
173 endforeach;
174