PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.5
YayMail – WooCommerce Email Customizer v4.4.5
4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 All 57 releases
yaymail / src / Abstracts / BaseTemplate.php

BaseTemplate.php in YayMail – WooCommerce Email Customizer 4.4.5, at src/Abstracts/BaseTemplate.php

217 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Abstracts;
4
5 use YayMail\Utils\TemplateHelpers;
6
7 /**
8 * Base class for code-defined email templates in Template Library.
9 */
10 abstract class BaseTemplate {
11 /**
12 * Unique identifier for this library template (slug style).
13 *
14 * @var string
15 */
16 protected $id = '';
17
18 /**
19 * YayMail email/template name that this library template applies to.
20 *
21 * Example: 'new_order', 'customer_completed_order', etc.
22 *
23 * @var string
24 */
25 protected $email_type;
26
27 /**
28 * Human-readable template name shown in the UI.
29 *
30 * @var string
31 */
32 protected $name;
33
34 /**
35 * Short description for the template card.
36 *
37 * @var string
38 */
39 protected $description;
40
41 /**
42 * Categories for filtering templates in the UI.
43 *
44 * @var array
45 */
46 protected $categories = [];
47
48 /**
49 * Optional position for ordering in the UI.
50 *
51 * @var int
52 */
53 protected $position = 10;
54
55 /**
56 * Whether this template is currently available.
57 *
58 * @var bool
59 */
60 protected $available = true;
61
62 /**
63 * Access level for this template.
64 *
65 * Supported values:
66 * - 'free' => always available
67 * - 'pro' => available only when a Pro variant of YayMail is installed
68 * - 'coming_soon' => not yet available
69 *
70 * @var string
71 */
72 protected $access = 'free';
73
74 /**
75 * Elements for the template.
76 *
77 * @var array
78 */
79 protected $elements = [];
80
81 /**
82 * Template-level email settings applied when using this template.
83 *
84 * @var array
85 */
86 protected $template_settings = [];
87
88 /**
89 * Last updated date of the template.
90 *
91 * @var string
92 */
93 protected $modified_date = '';
94
95 public function __construct() {
96 }
97
98 public function get_email_type() {
99 return $this->email_type;
100 }
101
102 public function get_id() {
103 return $this->id;
104 }
105
106 public function get_name() {
107 return $this->name;
108 }
109
110 public function get_description() {
111 return $this->description;
112 }
113
114 public function get_categories() {
115 return $this->categories;
116 }
117
118 public function get_available() {
119 return $this->available;
120 }
121
122 public function get_position() {
123 return $this->position;
124 }
125
126 public function get_elements() {
127 return $this->elements;
128 }
129
130 public function get_access() {
131 return $this->access;
132 }
133
134 public function get_email_settings() {
135 return $this->template_settings;
136 }
137
138 public function get_modified_date() {
139 return $this->modified_date;
140 }
141
142 /**
143 * Get full template payload including elements.
144 *
145 * @return array
146 */
147 public function get_template_data() {
148 // Always recompute availability before exposing data to REST.
149 $this->available = $this->determine_availability();
150
151 $elements = TemplateHelpers::normalize_elements_parent_ids( $this->get_elements() );
152
153 $data = [
154 'id' => $this->get_id(),
155 'email_type' => $this->get_email_type(),
156 'name' => $this->get_name(),
157 'description' => $this->get_description(),
158 'categories' => $this->get_categories(),
159 'position' => $this->get_position(),
160 'modified_date' => $this->get_modified_date(),
161 'available' => $this->get_available(),
162 'access' => $this->get_access(),
163 'elements' => $elements,
164 'email_settings' => $this->get_email_settings(),
165 ];
166
167 return $data;
168 }
169
170 /**
171 * Determine whether this template is available
172 *
173 * @return bool
174 */
175 protected function determine_availability() {
176 $access = $this->get_access();
177
178 if ( 'coming_soon' === $access ) {
179 return false;
180 }
181
182 if ( 'pro' === $access ) {
183 return $this->is_pro_version_installed();
184 }
185
186 return true;
187 }
188
189 /**
190 * Check whether a Pro variant of YayMail is installed.
191 *
192 * @return bool
193 */
194 protected function is_pro_version_installed() {
195 static $is_pro_cache = null;
196
197 if ( null !== $is_pro_cache ) {
198 return (bool) $is_pro_cache;
199 }
200
201 if ( ! function_exists( 'get_plugins' ) ) {
202 require_once ABSPATH . 'wp-admin/includes/plugin.php';
203 }
204
205 $all_plugins = function_exists( 'get_plugins' ) ? get_plugins() : [];
206
207 if ( empty( $all_plugins ) || ! is_array( $all_plugins ) ) {
208 $is_pro_cache = false;
209 return false;
210 }
211
212 $is_pro_cache = array_key_exists( 'yaymail-pro/yaymail.php', $all_plugins )
213 || array_key_exists( 'email-customizer-for-woocommerce/yaymail.php', $all_plugins );
214
215 return (bool) $is_pro_cache;
216 }
217 }