PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.21
Timetics – Appointment Booking Calendar & Scheduling v1.0.21
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.21, at core/emails/email.php

165 lines 3.7 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 * Add email footer
84 *
85 * @return void
86 */
87 public function add_email_footer() {
88 include TIMETICS_PLUGIN_DIR . '/templates/emails/email-footer.php';
89 }
90
91 /**
92 * Get email content
93 *
94 * @return string
95 */
96 public function get_template_content() {
97 ob_start();
98 $this->add_email_body();
99 $template = ob_get_clean();
100
101 return $template;
102
103 }
104
105 /**
106 * Send email using email template
107 *
108 * @return bool
109 */
110 public function send() {
111 $headers = $this->get_headers();
112 $subject = $this->get_subject();
113 $to = $this->get_recipient();
114 $message = $this->get_template_content();
115
116 /**
117 * Added temporary for leagacy sass. It will remove in future.
118 */
119 $data = apply_filters( 'timetics/admin/email/send', [$to, $subject, $message, $headers] );
120
121 return wp_mail( ...$data );
122 }
123
124 public function sanitize_content( $content ) {
125 // Define the allowed HTML tags and attributes
126 $allowed_tags = array(
127 'a' => array(
128 'href' => true,
129 'title' => true,
130 ),
131 'abbr' => array(
132 'title' => true,
133 ),
134 'acronym' => array(
135 'title' => true,
136 ),
137 'b' => array(),
138 'blockquote' => array(
139 'cite' => true,
140 ),
141 'cite' => array(),
142 'code' => array(),
143 'del' => array(
144 'datetime' => true,
145 ),
146 'em' => array(),
147 'i' => array(),
148 'q' => array(
149 'cite' => true,
150 ),
151 'img' => array (
152 'src' => true,
153 'data-*' => true
154 ),
155 'strike' => array(),
156 'strong' => array(),
157 );
158
159 $sanitized_content = wp_kses( $content, $allowed_tags );
160
161 return $sanitized_content;
162 }
163
164 }
165