| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_EN_Delete_Ticket' ) ) : |
| 7 |
|
| 8 |
final class WPSC_EN_Delete_Ticket extends WPSC_Email_Notifications { |
| 9 |
|
| 10 |
/** |
| 11 |
* Slug for this event (must be unique) |
| 12 |
* |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
private static $slug = 'delete-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_delete_ticket', array( __CLASS__, 'process_event' ), 200 ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Load this event for email notifications |
| 35 |
* |
| 36 |
* @param array $events - event. |
| 37 |
* @return array |
| 38 |
*/ |
| 39 |
public static function load_event( $events ) { |
| 40 |
|
| 41 |
$events[ self::$slug ] = esc_attr__( 'Delete ticket', 'supportcandy' ); |
| 42 |
return $events; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Process emails for this event |
| 47 |
* |
| 48 |
* @param WPSC_Ticket $ticket - ticket info. |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
public static function process_event( $ticket ) { |
| 52 |
|
| 53 |
$gs = get_option( 'wpsc-en-general' ); |
| 54 |
$email_templates = get_option( 'wpsc-email-templates', array() ); |
| 55 |
|
| 56 |
foreach ( $email_templates as $key => $et ) { |
| 57 |
|
| 58 |
if ( $et['event'] != self::$slug ) { |
| 59 |
continue; |
| 60 |
} |
| 61 |
|
| 62 |
// email notification object. |
| 63 |
$en = new self(); |
| 64 |
|
| 65 |
// set properties. |
| 66 |
$en->ticket = $ticket; |
| 67 |
|
| 68 |
// set template. |
| 69 |
$en->template = $et; |
| 70 |
$en->template_key = $key; |
| 71 |
|
| 72 |
// check whether conditions matches (if any). |
| 73 |
if ( ! $en->is_valid() ) { |
| 74 |
continue; |
| 75 |
} |
| 76 |
|
| 77 |
// macro attachments. |
| 78 |
$en->attachments = array_merge( $en->attachments, WPSC_Macros::$attachments ); |
| 79 |
WPSC_Macros::$attachments = array(); |
| 80 |
|
| 81 |
$en = apply_filters( 'wpsc_en_before_sending', $en ); |
| 82 |
|
| 83 |
// send an email. |
| 84 |
$attachment_ids = array(); |
| 85 |
foreach ( $en->attachments as $attachment ) { |
| 86 |
$attachment_ids[] = $attachment->id; |
| 87 |
} |
| 88 |
|
| 89 |
WPSC_Background_Email::insert( |
| 90 |
array( |
| 91 |
'from_name' => $en->from_name, |
| 92 |
'from_email' => $en->from_email, |
| 93 |
'reply_to' => $gs['reply-to'], |
| 94 |
'subject' => $en->subject, |
| 95 |
'body' => $en->body, |
| 96 |
'to_email' => implode( '|', $en->to ), |
| 97 |
'cc_email' => implode( '|', $en->cc ), |
| 98 |
'bcc_email' => implode( '|', $en->bcc ), |
| 99 |
'attachments' => implode( '|', $attachment_ids ), |
| 100 |
'priority' => 2, |
| 101 |
) |
| 102 |
); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
endif; |
| 107 |
|
| 108 |
WPSC_EN_Delete_Ticket::init(); |
| 109 |
|