PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 4.0.0
WP 2FA – Two-factor authentication for WordPress v4.0.0
4.0.0 1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / includes / classes / class-email-template.php
wp-2fa / includes / classes Last commit date
Admin 14 hours ago App 14 hours ago Authenticator 14 hours ago Free 14 hours ago Licensing 14 hours ago Shortcodes 14 hours ago Utils 14 hours ago bacon 14 hours ago dasprid 14 hours ago class-email-template.php 14 hours ago class-wp2fa.php 14 hours ago index.php 14 hours ago
class-email-template.php
145 lines
1 <?php
2 /**
3 * Responsible for email templates generation.
4 *
5 * @package wp2fa
6 * @copyright 2026 Melapress
7 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
8 * @link https://wordpress.org/plugins/wp-2fa/
9 */
10
11 namespace WP2FA;
12
13 if ( ! class_exists( '\WP2FA\Email_Template' ) ) {
14
15 /**
16 * Plain old PHP object to hold data for an email template.
17 *
18 * @package WP2FA
19 */
20 class Email_Template {
21
22 /**
23 * Template ID used for most settings form fields and setting keys.
24 *
25 * @var string
26 */
27 private $id;
28
29 /**
30 * The title of the email
31 *
32 * @var string
33 */
34 private $title;
35
36 /**
37 * Email template description
38 *
39 * @var string
40 */
41 private $description;
42
43 /**
44 * ID used for identifying the subject and body of the email. Defaults to $id.
45 *
46 * @var string ID used for identifying the subject and body of the email. Defaults to $id.
47 */
48 private $email_content_id;
49
50 /**
51 * True if the email can be turned on or off in the plugin settings.
52 *
53 * @var bool
54 */
55 private $can_be_toggled = true;
56
57 /**
58 * Email_Template constructor.
59 *
60 * @param string $id - The template ID.
61 * @param string $title - The title.
62 * @param string $description - The description.
63 */
64 public function __construct( string $id, string $title, string $description ) {
65 $this->id = $this->sanitize_input( $id );
66 $this->title = $this->sanitize_input( $title );
67 $this->description = $this->sanitize_input( $description );
68 $this->email_content_id = $this->sanitize_input( $id );
69 }
70
71 /**
72 * Can it be toggled
73 *
74 * @return bool
75 */
76 public function can_be_toggled(): bool {
77 return $this->can_be_toggled;
78 }
79
80 /**
81 * Sets the toggled flag for the template
82 *
83 * @param bool $can_be_toggled - Can it be toggled.
84 */
85 public function set_can_be_toggled( $can_be_toggled ) {
86 $this->can_be_toggled = filter_var( $can_be_toggled, FILTER_VALIDATE_BOOLEAN );
87 }
88
89 /**
90 * Returns the template ID
91 *
92 * @return string
93 */
94 public function get_id(): string {
95 return $this->id;
96 }
97
98 /**
99 * Returns the title
100 *
101 * @return string
102 */
103 public function get_title(): string {
104 return $this->title;
105 }
106
107 /**
108 * Returns the description
109 *
110 * @return string
111 */
112 public function get_description(): string {
113 return $this->description;
114 }
115
116 /**
117 * Returns the mail content
118 *
119 * @return string
120 */
121 public function get_email_content_id(): string {
122 return $this->email_content_id;
123 }
124
125 /**
126 * Set content ID
127 *
128 * @param string $email_content_id - the ID of the content.
129 */
130 public function set_email_content_id( string $email_content_id ) {
131 $this->email_content_id = $this->sanitize_input( $email_content_id );
132 }
133
134 /**
135 * Sanitize input data
136 *
137 * @param string $input - The input data.
138 * @return string - The sanitized input data.
139 */
140 private function sanitize_input( string $input ): string {
141 return htmlspecialchars( strip_tags( $input ), ENT_QUOTES, 'UTF-8' );
142 }
143 }
144 }
145