| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Core\Hooks; |
| 4 |
|
| 5 |
use Yatra\Core\Admin\Emails\AdminEmail; |
| 6 |
use Yatra\Core\Admin\Emails\CustomerEmail; |
| 7 |
|
| 8 |
class EmailHooks |
| 9 |
{ |
| 10 |
|
| 11 |
public static function init() |
| 12 |
{ |
| 13 |
$self = new self; |
| 14 |
|
| 15 |
add_action('init', array($self, 'preview_email')); |
| 16 |
|
| 17 |
} |
| 18 |
|
| 19 |
public function preview_email() |
| 20 |
{ |
| 21 |
if (!current_user_can('manage_yatra')) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
$preview_action = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : ''; |
| 26 |
|
| 27 |
$type = isset($_GET['email_type']) ? sanitize_text_field($_GET['email_type']) : ''; |
| 28 |
|
| 29 |
$to = isset($_GET['email_to']) ? sanitize_text_field($_GET['email_to']) : ''; |
| 30 |
|
| 31 |
if ($preview_action != 'yatra-email-preview' || $type === '' || $to === '') { |
| 32 |
return; |
| 33 |
} |
| 34 |
$valid_to_array = array('admin', 'customer'); |
| 35 |
|
| 36 |
$valid_type_array = array('booking', 'booking_status_change', 'enquiry'); |
| 37 |
|
| 38 |
if (!in_array($to, $valid_to_array, true) || !in_array($type, $valid_type_array, true)) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
if ($type === "booking" && $to === "admin") { |
| 43 |
|
| 44 |
echo AdminEmail::get_booking_completed_message(); |
| 45 |
|
| 46 |
} else if ($type === "booking" && $to === "customer") { |
| 47 |
|
| 48 |
echo CustomerEmail::get_booking_completed_message(); |
| 49 |
|
| 50 |
} else if ($type === "booking_status_change" && $to === "admin") { |
| 51 |
|
| 52 |
echo AdminEmail::get_booking_status_change_message(); |
| 53 |
|
| 54 |
} else if ($type === "booking_status_change" && $to === "customer") { |
| 55 |
|
| 56 |
echo CustomerEmail::get_booking_status_change_message(); |
| 57 |
|
| 58 |
} else if ($type === 'enquiry' && $to === 'admin') { |
| 59 |
|
| 60 |
echo AdminEmail::get_enquiry_form_saved_message(); |
| 61 |
} |
| 62 |
|
| 63 |
exit; |
| 64 |
} |
| 65 |
} |