PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.3.9
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.3.9
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-create-ticket.php

class-wpsc-en-create-ticket.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.3.9, at includes/admin/email-notifications/class-wpsc-en-create-ticket.php

130 lines 3.2 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_Create_Ticket' ) ) :
7
8 final class WPSC_EN_Create_Ticket extends WPSC_Email_Notifications {
9
10 /**
11 * Slug for this event (must be unique)
12 *
13 * @var string
14 */
15 private static $slug = 'create-ticket';
16
17 /**
18 * Ticket object
19 *
20 * @var WPSC_Ticket
21 */
22 public $ticket;
23
24 /**
25 * Initialize this class
26 */
27 public static function init() {
28
29 // process event.
30 add_action( 'wpsc_create_new_ticket', array( __CLASS__, 'process_event' ), 200 );
31 }
32
33 /**
34 * Process emails for this event
35 *
36 * @param WPSC_Ticket $ticket - ticket info.
37 * @return void
38 */
39 public static function process_event( $ticket ) {
40
41 $gs = get_option( 'wpsc-en-general' );
42 $email_templates = get_option( 'wpsc-email-templates', array() );
43
44 foreach ( $email_templates as $key => $et ) {
45
46 if ( $et['event'] != self::$slug ) {
47 continue;
48 }
49
50 // email notification object.
51 $en = new self();
52
53 // set properties.
54 $en->ticket = $ticket;
55
56 // set template.
57 $en->template = $et;
58 $en->template_key = $key;
59
60 // check whether conditions matches (if any).
61 if ( ! $en->is_valid() ) {
62 continue;
63 }
64
65 // Ticket attachments.
66 $thread = $ticket->get_description_thread();
67 if ( $thread && $thread->attachments ) {
68 foreach ( $thread->attachments as $attachment ) :
69 $en->attachments[] = $attachment;
70 endforeach;
71 }
72
73 // macro attachments.
74 $en->attachments = array_merge( $en->attachments, WPSC_Macros::$attachments );
75 WPSC_Macros::$attachments = array();
76
77 $en = apply_filters( 'wpsc_en_before_sending', $en );
78
79 $advanced = get_option( 'wpsc-ms-advanced-settings' );
80 if ( $advanced['do-not-notify-owner'] && isset( $_POST['notify_owner'] ) ) { // phpcs:ignore
81
82 if ( in_array( $ticket->customer->email, $en->to ) ) {
83 unset( $en->to[ array_search( $ticket->customer->email, $en->to ) ] );
84 }
85 if ( in_array( $ticket->customer->email, $en->cc ) ) {
86 unset( $en->cc[ array_search( $ticket->customer->email, $en->cc ) ] );
87 }
88 if ( in_array( $ticket->customer->email, $en->bcc ) ) {
89 unset( $en->bcc[ array_search( $ticket->customer->email, $en->bcc ) ] );
90 }
91 }
92
93 if ( ! $en->to ) {
94
95 $other_emails = array_merge( $en->cc, $en->bcc );
96 if ( $other_emails ) {
97 $en->to[] = $other_emails[0];
98 } else {
99 continue;
100 }
101 }
102
103 // send an email.
104 $attachment_ids = array();
105 foreach ( $en->attachments as $attachment ) {
106 $attachment_ids[] = $attachment->id;
107 }
108
109 $data = array(
110 'from_name' => $en->from_name,
111 'from_email' => $en->from_email,
112 'reply_to' => $gs['reply-to'],
113 'subject' => $en->subject,
114 'body' => $en->body,
115 'to_email' => implode( '|', $en->to ),
116 'cc_email' => implode( '|', $en->cc ),
117 'bcc_email' => implode( '|', $en->bcc ),
118 'attachments' => implode( '|', $attachment_ids ),
119 'priority' => 1,
120 );
121 $data = apply_filters( 'wpsc_create_ticket_email_data', $data, $thread );
122
123 WPSC_Background_Email::insert( $data );
124 }
125 }
126 }
127 endif;
128
129 WPSC_EN_Create_Ticket::init();
130