PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.3
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.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 / admin / email-notifications / class-wpsc-en-add-private-note.php

class-wpsc-en-add-private-note.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.4.3, at includes/admin/email-notifications/class-wpsc-en-add-private-note.php

137 lines 3.1 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_EN_Add_Private_Note' ) ) :
7
8 final class WPSC_EN_Add_Private_Note extends WPSC_Email_Notifications {
9
10 /**
11 * Slug for this event (must be unique)
12 *
13 * @var string
14 */
15 private static $slug = 'submit-note';
16
17 /**
18 * Ticket object
19 *
20 * @var WPSC_Ticket
21 */
22 public $ticket;
23
24 /**
25 * Thread object
26 *
27 * @var WPSC_Thread
28 */
29 public $thread;
30
31 /**
32 * Initialize this class
33 */
34 public static function init() {
35
36 // process event.
37 add_action( 'wpsc_submit_note', array( __CLASS__, 'process_event' ), 200 );
38 }
39
40 /**
41 * Process emails for this event
42 * Ignore phpcs nonce issue as we already checked where it is called from.
43 *
44 * @param WPSC_Thread $thread - thread.
45 * @return void
46 */
47 public static function process_event( $thread ) {
48
49 $gs = get_option( 'wpsc-en-general' );
50 $email_templates = get_option( 'wpsc-email-templates', array() );
51
52 foreach ( $email_templates as $key => $et ) {
53
54 if ( $et['event'] != self::$slug ) {
55 continue;
56 }
57
58 // email notification object.
59 $en = new self();
60
61 // set properties.
62 $en->ticket = $thread->ticket;
63 $en->thread = $thread;
64
65 // set template.
66 $en->template = $et;
67 $en->template_key = $key;
68
69 // check whether conditions matches (if any).
70 if ( ! $en->is_valid() ) {
71 continue;
72 }
73
74 // phpcs:disable
75 // cc emails provided in note.
76 $cc = isset( $_POST['cc'] ) ? array_unique(
77 array_filter(
78 array_map(
79 'sanitize_email',
80 explode( ',', sanitize_text_field( wp_unslash( $_POST['cc'] ) ) )
81 )
82 )
83 ) : array();
84 $en->cc = array_merge( $en->cc, $cc );
85
86 // bcc emails provided in note.
87 $bcc = isset( $_POST['bcc'] ) ? array_unique(
88 array_filter(
89 array_map(
90 'sanitize_email',
91 explode( ',', sanitize_text_field( wp_unslash( $_POST['bcc'] ) ) )
92 )
93 )
94 ) : array();
95 $en->bcc = array_merge( $en->bcc, $bcc );
96 // phpcs:enable
97
98 // Thread attachments.
99 if ( $thread->attachments ) {
100 foreach ( $thread->attachments as $attachment ) :
101 $en->attachments[] = $attachment;
102 endforeach;
103 }
104
105 // macro attachments.
106 $en->attachments = array_merge( $en->attachments, WPSC_Macros::$attachments );
107 WPSC_Macros::$attachments = array();
108
109 $en = apply_filters( 'wpsc_en_before_sending', $en );
110
111 // send an email.
112 $attachment_ids = array();
113 foreach ( $en->attachments as $attachment ) {
114 $attachment_ids[] = $attachment->id;
115 }
116
117 WPSC_Background_Email::insert(
118 array(
119 'from_name' => $en->from_name,
120 'from_email' => $en->from_email,
121 'reply_to' => $gs['reply-to'],
122 'subject' => $en->subject,
123 'body' => $en->body,
124 'to_email' => implode( '|', $en->to ),
125 'cc_email' => implode( '|', $en->cc ),
126 'bcc_email' => implode( '|', $en->bcc ),
127 'attachments' => implode( '|', $attachment_ids ),
128 'priority' => 1,
129 )
130 );
131 }
132 }
133 }
134 endif;
135
136 WPSC_EN_Add_Private_Note::init();
137