PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.11
Timetics – Appointment Booking Calendar & Scheduling v1.0.11
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / core / emails / email.php

email.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.11, at core/emails/email.php

125 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Core email class
4 *
5 * @package Timetics
6 */
7
8 namespace Timetics\Core\Emails;
9
10 /**
11 * Class Email
12 */
13 abstract class Email {
14 /**
15 * Constructor for core email class
16 *
17 * @return void
18 */
19 public function __construct() {
20 add_action( 'timetics-email-header', [$this, 'add_email_header'] );
21 add_action( 'timetics-email-footer', [$this, 'add_email_footer'] );
22 add_action( 'timetics-email-body', [$this, 'add_email_body'] );
23 }
24
25 /**
26 * Get email subject
27 *
28 * @return string
29 */
30 abstract public function get_subject();
31
32 /**
33 * Get email html template
34 *
35 * @return string
36 */
37 abstract public function get_template();
38
39 /**
40 * Get email recipent
41 *
42 * @return string
43 */
44 abstract public function get_recipient();
45
46 /**
47 * Get email header
48 *
49 * @return string
50 */
51 public function get_headers() {
52 $headers = 'MIME-Version: 1.0' . "\r\n";
53 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
54
55 return $headers;
56 }
57
58 /**
59 * Add email header
60 *
61 * @return void
62 */
63 public function add_email_header() {
64 include TIMETICS_PLUGIN_DIR . '/templates/emails/email-header.php';
65 }
66
67 /**
68 * Add email body
69 *
70 * @return void
71 */
72 public function add_email_body() {
73 $template = $this->get_template();
74
75 if ( file_exists( $template ) ) {
76 ob_start(); // Start output buffering
77 include $template;
78 $body = ob_get_clean(); // Retrieve and clean output buffer
79 echo wp_kses_post( $body ); // Output the email body
80 }
81 }
82
83 /**
84 * Add email footer
85 *
86 * @return void
87 */
88 public function add_email_footer() {
89 include TIMETICS_PLUGIN_DIR . '/templates/emails/email-footer.php';
90 }
91
92 /**
93 * Get email content
94 *
95 * @return string
96 */
97 public function get_template_content() {
98 ob_start();
99 $this->add_email_body();
100 $template = ob_get_clean();
101
102 return $template;
103
104 }
105
106 /**
107 * Send email using email template
108 *
109 * @return bool
110 */
111 public function send() {
112 $headers = $this->get_headers();
113 $subject = $this->get_subject();
114 $to = $this->get_recipient();
115 $message = $this->get_template_content();
116
117 /**
118 * Added temporary for leagacy sass. It will remove in future.
119 */
120 $data = apply_filters( 'timetics/admin/email/send', [$to, $subject, $message, $headers] );
121
122 return wp_mail( ...$data );
123 }
124 }
125