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_note.php

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

172 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' => 'private_note',
29 'compare' => '='
30 ),
31 ),
32 ]);
33
34
35 $email_subject = get_option('wpsc_email_notification_subject');
36 $email_body = get_option('wpsc_email_notification_body');
37
38 foreach ($email_templates as $email) :
39
40 $conditions = get_term_meta($email->term_id,'conditions',true);
41 if( $wpscfunction->check_ticket_conditions($conditions,$ticket_id) ) :
42
43 $subject = $wpscfunction->replace_macro($email_subject['email_subject_' . $email->term_id], $ticket_id);
44 $subject = '['.get_option('wpsc_ticket_alice','').$ticket_id.'] '.stripslashes($subject);
45 $body = $wpscfunction->replace_macro(stripslashes($email_body['email_body_' . $email->term_id]), $ticket_id);
46 $recipients = get_term_meta($email->term_id,'recipients',true);
47 $extra_recipients = get_term_meta($email->term_id,'extra_recipients',true);
48
49 $email_addresses = array();
50 foreach ($recipients as $recipient) {
51 if(is_numeric($recipient)){
52 $agents = get_terms([
53 'taxonomy' => 'wpsc_agents',
54 'hide_empty' => false,
55 'meta_query' => array(
56 'relation' => 'AND',
57 array(
58 'key' => 'role',
59 'value' => $recipient,
60 'compare' => '='
61 ),
62 ),
63 ]);
64 foreach ($agents as $agent) {
65 $user_id = get_term_meta($agent->term_id,'user_id',true);
66 if($user_id){
67 $user = get_user_by('id',$user_id);
68 $email_addresses[] = $user->user_email;
69 }
70 }
71 } else {
72 switch ($recipient) {
73 case 'customer':
74 $customer_email = $wpscfunction->get_ticket_fields($ticket_id,'customer_email');
75 $email_addresses[] = $customer_email;
76 break;
77 case 'assigned_agent':
78 $email_addresses = array_merge($email_addresses,$wpscfunction->get_assigned_agent_emails($ticket_id));
79 break;
80 case 'previously_assigned_agent':
81 $email_addresses = array_merge($email_addresses,$wpscfunction->get_previously_assigned_agents($ticket_id));
82 break;
83 case 'extra_ticket_users' :
84 $extra_users = $wpscfunction->get_ticket_meta($ticket_id,'extra_ticket_users');
85 $email_addresses = array_merge($email_addresses, $extra_users);
86 break;
87 }
88 }
89 }
90 if(isset($extra_recipients[0]) && $extra_recipients[0] ) {
91 $email_addresses = array_merge($email_addresses,$extra_recipients);
92 }
93
94 $bcc = isset($_POST['reply_bcc']) ? trim($_POST['reply_bcc']) : '';
95 if ($bcc) {
96 $bcc = array_filter(array_map('sanitize_email', explode(',', $bcc)));
97 $email_addresses = array_merge($email_addresses, $bcc);
98 }
99
100 $last_note = $wpscfunction->get_last_note($ticket_id);
101 if(in_array('current_user', $recipients)){
102 $email_addresses[] = $last_note['user_email'];
103 }else{
104 $email_addresses = array_diff($email_addresses,array($last_note['user_email']));
105 }
106 $email_addresses = apply_filters('wpsc_en_submit_note_email_addresses',$email_addresses,$email,$thread_id,$ticket_id);
107 $email_addresses = array_values($email_addresses);
108
109 if ($ignore_emails) {
110 $ignore_emails = array_map('trim', $ignore_emails);
111 $email_addresses = array_map('trim', $email_addresses);
112 foreach ($ignore_emails as $ignore_email) {
113 foreach($email_addresses as $index => $email){
114 if(fnmatch($ignore_email, $email)){
115 unset($email_addresses[$index]);
116 }
117 }
118 }
119 }
120 $email_addresses = array_unique($email_addresses);
121 $email_addresses = array_values($email_addresses);
122
123 $to = isset($email_addresses[0])? $email_addresses[0] : '';
124 if($to){
125 unset($email_addresses[0]);
126 } else {
127 continue; // no email address found to send. So go to next foreach iteration.
128 }
129
130 $from_email = apply_filters('wpsc_add_note_from_email_headers',$from_email,$ticket_id);
131 $reply_to = apply_filters('wpsc_add_note_ticket_replyto_headers',$reply_to,$ticket_id);
132
133 $bcc = implode(',',$email_addresses);
134
135 $to = apply_filters('wpsc_submit_note_to_email',$to,$email_addresses,$ticket_id);
136 $bcc = apply_filters('wpsc_submit_note_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_note',
149
150 );
151 if($wpsc_email_sending_method){
152 $wpdb->insert( $wpdb->prefix . 'wpsc_email_notification',$args);
153
154 }else{
155 $headers = "From: {$from_name} <{$from_email}>\r\n";
156 $headers .= "Reply-To: {$reply_to}\r\n";
157 $email_addresses = explode(',',$bcc);
158 foreach ($email_addresses as $email_address) {
159 if(strlen($email_address)) $headers .= "BCC: {$email_address}\r\n";
160 }
161
162 $headers .= "Content-Type: text/html; charset=utf-8\r\n";
163
164 wp_mail($to, $subject, $body, $headers);
165 }
166
167 do_action('wpsc_after_submit_note_mail',$ticket_id,$args);
168
169 endif;
170
171 endforeach;
172