PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
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
← All changes | includes/class-wpsc-email-notifications.php +53 -9 3.3.9 → 3.5.4 View file →
@@ -63,8 +63,15 @@
63 63 */
64 64 public $body;
65 65
66 66 /**
67 + * Ticket object this notification is for
68 + *
69 + * @var WPSC_Ticket
70 + */
71 + public $ticket;
72 +
73 + /**
67 74 * Email notification template
68 75 *
69 76 * @var Array
70 77 */
@@ -120,8 +127,30 @@
120 127 * @return void
121 128 */
122 129 public static function send_background_emails() {
123 130
131 + if ( get_transient( 'wpsc_email_cron_lock' ) ) {
132 + return;
133 + }
134 +
135 + $gs = get_option( 'wpsc-en-general' );
136 + $ttl = max( 30, (int) $gs['cron-email-count'] * 2 );
137 + set_transient( 'wpsc_email_cron_lock', time(), $ttl );
138 +
139 + try {
140 + self::process_queue();
141 + } finally {
142 + delete_transient( 'wpsc_email_cron_lock' );
143 + }
144 + }
145 +
146 + /**
147 + * Process email queue
148 + *
149 + * @return void
150 + */
151 + public static function process_queue() {
152 +
124 153 $gs = get_option( 'wpsc-en-general' );
125 154 $count = $gs['cron-email-count'];
126 155
127 156 $emails = WPSC_Background_Email::find(
@@ -160,10 +189,15 @@
160 189 public function send() {
161 190
162 191 $en = get_option( 'wpsc-en-general' );
163 192 // headers.
164 - $headers = "From: {$this->from_name} <{$this->from_email}>\r\n";
165 - $headers .= "Reply-To: {$this->reply_to}\r\n";
193 + $headers = '';
194 + if ( $this->from_name && $this->from_email ) {
195 + $headers = "From: {$this->from_name} <{$this->from_email}>\r\n";
196 + }
197 + if ( $this->reply_to ) {
198 + $headers .= "Reply-To: {$this->reply_to}\r\n";
199 + }
166 200 foreach ( $this->cc as $email ) {
167 201 $headers .= "CC: {$email}\r\n";
168 202 }
169 203 foreach ( $this->bcc as $email ) {
@@ -183,10 +217,17 @@
183 217 if ( ! file_exists( $filepath ) ) {
184 218 mkdir( $filepath, 0777, true );
185 219 }
186 220 $filepath .= '/' . $attachment->name;
187 - copy( $upload_dir['basedir'] . $attachment->file_path, $filepath );
188 - $attachments[] = $filepath;
221 +
222 + $source = wp_normalize_path( $attachment->file_path );
223 + if ( ! is_file( $source ) ) {
224 + $source = trailingslashit( wp_normalize_path( $upload_dir['basedir'] ) ) . ltrim( $source, '/\\' );
225 + }
226 +
227 + if ( is_file( $source ) && copy( $source, $filepath ) ) {
228 + $attachments[] = $filepath;
229 + }
189 230 endforeach;
190 231 }
191 232
192 233 if ( is_rtl() ) {
@@ -226,16 +267,19 @@
226 267 if ( ! $this->template['is_enable'] ) {
227 268 return false;
228 269 }
229 270
271 + // check block notification flag in misc to skip notifications if it is set for the ticket.
272 + $misc_array = $this->ticket->misc ? $this->ticket->misc : array();
273 + if ( ! empty( $misc_array['block_notifications'] ) ) {
274 + return false;
275 + }
276 +
230 277 // from name & email.
231 278 $en_general = get_option( 'wpsc-en-general' );
232 - if ( ! $en_general['from-name'] || ! $en_general['from-email'] ) {
233 - return false;
234 - }
235 279
236 - $this->from_name = $en_general['from-name'];
237 - $this->from_email = $en_general['from-email'];
280 + $this->from_name = $en_general['from-name'] ? $en_general['from-name'] : '';
281 + $this->from_email = $en_general['from-email'] ? $en_general['from-email'] : '';
238 282 $this->reply_to = $en_general['reply-to'] ? $en_general['reply-to'] : $this->from_email;
239 283
240 284 // subject.
241 285 $this->set_subject();