PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.2
YayMail – WooCommerce Email Customizer v4.4.2
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 3.4.2 3.4.3 All 55 releases
yaymail / src / Abstracts / BaseTemplate.php

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

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