PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.5.5
EmailKit – Email Customizer for WooCommerce & WP v1.5.5
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / includes / Admin / TemplateList.php

TemplateList.php in EmailKit – Email Customizer for WooCommerce & WP 1.5.5, at includes/Admin/TemplateList.php

261 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace EmailKit\Admin;
3
4 use EmailKit\Admin\Emails\EmailLists;
5 defined( 'ABSPATH' ) || exit;
6
7 Class TemplateList{
8 const EMAILKIT_URL_TEMAPLTE_DIR = EMAILKIT_DIR. "includes/";
9 const EMAILKIT_URL_TEMAPLTE_URL = EMAILKIT_URL. "includes/";
10
11 public static function get_templates(){
12
13
14 $template_list = [
15 'template-1' => [
16 'id' => 1,
17 'package' => 'free',
18 'mail_type' => 'woocommerce',
19 'title' => EmailLists::NEW_ORDER,
20 'template_title' => EmailLists::woocommerce_email(EmailLists::NEW_ORDER),
21 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/new-order/1/preview-thumb.svg',
22 'demo-url' => 'https://wpmet.com/',
23 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/new-order/1/content.json',
24 ],
25 'template-2' => [
26 'id' => 2,
27 'package' => 'free',
28 'mail_type' => 'woocommerce',
29 'title' => EmailLists::CANCELLED_ORDER,
30 'template_title' => EmailLists::woocommerce_email(EmailLists::CANCELLED_ORDER),
31 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/cancelled-order/1/preview-thumb.svg',
32 'demo-url' => 'https://wpmet.com/',
33 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/cancelled-order/1/content.json',
34
35 ],
36 'template-3' => [
37 'id' => 3,
38 'package' => 'free',
39 'mail_type' => 'woocommerce',
40 'title' => EmailLists::FAILED_ORDER,
41 'template_title' => EmailLists::woocommerce_email(EmailLists::FAILED_ORDER),
42 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/failed-order/1/preview-thumb.svg',
43 'demo-url' => 'https://wpmet.com/',
44 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/failed-order/1/content.json',
45 ],
46 'template-4' => [
47 'id' => 4,
48 'package' => 'free',
49 'mail_type' => 'woocommerce',
50 'title' => EmailLists::ORDER_ON_HOLD,
51 'template_title' => EmailLists::woocommerce_email(EmailLists::ORDER_ON_HOLD),
52 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/order-on-hold/1/preview-thumb.svg',
53 'demo-url' => 'https://wpmet.com/',
54 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/order-on-hold/1/content.json',
55 ],
56 'template-5' => [
57 'id' => 5,
58 'package' => 'free',
59 'mail_type' => 'woocommerce',
60 'title' => EmailLists::PROCESSING_ORDER,
61 'template_title' => EmailLists::woocommerce_email(EmailLists::PROCESSING_ORDER),
62 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/processing-order/1/preview-thumb.svg',
63 'demo-url' => 'https://wpmet.com/',
64 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/processing-order/1/content.json',
65 ],
66 'template-6' => [
67 'id' => 6,
68 'package' => 'free',
69 'mail_type' => 'woocommerce',
70 'title' => EmailLists::COMPLETED_ORDER,
71 'template_title' => EmailLists::woocommerce_email(EmailLists::COMPLETED_ORDER),
72 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/completed-order/1/preview-thumb.svg',
73 'demo-url' => 'https://wpmet.com/',
74 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/completed-order/1/content.json'
75 ],
76 'template-7' => [
77 'id' => 7,
78 'package' => 'free',
79 'mail_type' => 'woocommerce',
80 'title' => EmailLists::REFUNDED_ORDER,
81 'template_title' => EmailLists::woocommerce_email(EmailLists::REFUNDED_ORDER),
82 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/refunded-order/1/preview-thumb.svg',
83 'demo-url' => 'https://wpmet.com/',
84 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/refunded-order/1/content.json'
85 ],
86 'template-8' => [
87 'id' => 8,
88 'package' => 'free',
89 'mail_type' => 'woocommerce',
90 'title' => EmailLists::CUSTOMER_INVOICE_OR_ORDER_DETAILS,
91 'template_title' => EmailLists::woocommerce_email(EmailLists::CUSTOMER_INVOICE_OR_ORDER_DETAILS),
92 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/customer-invoice/1/preview-thumb.svg',
93 'demo-url' => '',
94 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/customer-invoice/1/content.json'
95 ],
96 'template-9' => [
97 'id' => 9,
98 'package' => 'free',
99 'mail_type' => 'woocommerce',
100 'title' => EmailLists::CUSTOMER_NOTE,
101 'template_title' => EmailLists::woocommerce_email(EmailLists::CUSTOMER_NOTE),
102 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/customer-note/1/preview-thumb.svg',
103 'demo-url' => 'https://wpmet.com/',
104 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/customer-note/1/content.json'
105 ],
106 'template-10' => [
107 'id' => 10,
108 'package' => 'free',
109 'mail_type' => 'woocommerce',
110 'title' => EmailLists::NEW_ACCOUNT,
111 'template_title' => EmailLists::woocommerce_email(EmailLists::NEW_ACCOUNT),
112 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/wc-new-account/1/preview-thumb.svg',
113 'demo-url' => 'https://wpmet.com/',
114 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/wc-new-account/1/content.json'
115 ],
116
117 'template-11' => [
118 'id' => 11,
119 'package' => 'free',
120 'mail_type' => 'woocommerce',
121 'title' => EmailLists::RESET_PASSWORD,
122 'template_title' => EmailLists::woocommerce_email(EmailLists::RESET_PASSWORD),
123 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/wc-reset-password/1/preview-thumb.svg',
124 'demo-url' => 'https://wpmet.com/',
125 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/wc-reset-password/1/content.json'
126 ],
127 'template-12' => [
128 'id' => 12,
129 'package' => 'free',
130 'mail_type' => 'woocommerce',
131 'title' => EmailLists::LOW_STOCK,
132 'template_title' => EmailLists::woocommerce_email(EmailLists::LOW_STOCK),
133 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/low-stock/1/preview-thumb.svg',
134 'demo-url' => 'https://wpmet.com/',
135 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/low-stock/1/content.json'
136 ],
137 'template-13' => [
138 'id' => 13,
139 'package' => 'free',
140 'mail_type' => 'woocommerce',
141 'title' => EmailLists::NO_STOCK,
142 'template_title' => EmailLists::woocommerce_email(EmailLists::NO_STOCK),
143 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/no-stock/1/preview-thumb.svg',
144 'demo-url' => 'https://wpmet.com/',
145 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/no-stock/1/content.json'
146 ],
147 'template-14' => [
148 'id' => 14,
149 'package' => 'free',
150 'mail_type' => 'woocommerce',
151 'title' => EmailLists::BACK_ORDER,
152 'template_title' => EmailLists::woocommerce_email(EmailLists::BACK_ORDER),
153 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/back-order/1/preview-thumb.svg',
154 'demo-url' => 'https://wpmet.com/',
155 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/back-order/1/content.json'
156 ],
157
158 'template-15' => [
159 'id' => 16,
160 'package' => 'free',
161 'mail_type' => 'wordpress',
162 'title' => EmailLists::WP_NEW_REGISTER,
163 'template_title' => EmailLists::wordpress_email(EmailLists::WP_NEW_REGISTER),
164 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/wp-new-register/1/preview-thumb.svg',
165 'demo-url' => 'https://wpmet.com/',
166 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/wp-new-register/1/content.json' ,
167 ],
168 'template-17' => [
169 'id' => 102,
170 'package' => 'free',
171 'mail_type' => 'wordpress',
172 'title' => EmailLists::WP_RESET_PASSWORD,
173 'template_title' => EmailLists::wordpress_email(EmailLists::WP_RESET_PASSWORD),
174 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/wp-reset-password/1/preview-thumb.svg',
175 'demo-url' => 'https://wpmet.com/',
176 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/wp-reset-password/1/content.json'
177 ],
178
179 'template-18' => [
180 'id' => 17,
181 'package' => 'free',
182 'mail_type' => 'woocommerce',
183 'title' => EmailLists::PARTIAL_REFUND,
184 'template_title' => EmailLists::woocommerce_email(EmailLists::PARTIAL_REFUND),
185 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/partial-refund/1/preview-thumb.svg',
186 'demo-url' => 'https://wpmet.com/',
187 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/partial-refund/1/content.json'
188 ],
189
190
191
192 ];
193
194 return apply_filters( 'emailkit/editor/templates', $template_list );
195 }
196
197
198 public static function get(){
199
200 $email_types = [
201
202 'wordpress' => __('WordPress Email', 'emailkit'),
203 ];
204
205 // Include necessary WordPress files
206 // require_once ABSPATH . 'wp-admin/includes/plugin.php';
207 // require_once ABSPATH . 'wp-includes/class-wp.php'; // Adjust the path if necessary
208
209
210 if(is_plugin_active(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php')){
211 $email_types['woocommerce'] = __('Woocommerce email', 'emailkit');
212 }
213
214 return apply_filters('emailkit_email_types',$email_types);
215 }
216
217
218 /**
219 * Get template list by form type
220 *
221 * @param string $mail_type
222 * @return array
223 */
224 public function get_templates_by_mail_type( $mail_type ) {
225 $templates_list = [];
226
227 // array filter
228 $templates_list = array_filter( $this->get_templates(), function( $template ) use ( $mail_type ) {
229 if(isset($template['mail_type'])){
230 return $template['mail_type'] === $mail_type;
231 }
232
233 return true;
234 } );
235
236 return $templates_list;
237 }
238
239 public function get_template_contents($id){
240
241 if(!array_key_exists($id, $this->get_templates()) || !file_exists($this->get_templates()[$id]['file'])){
242 return null;
243 }
244
245 $template_file_url = self::abs_path_to_url($this->get_templates()[$id]['file']);
246 $content = wp_remote_get($template_file_url, ['sslverify' => false]);
247 $content = json_decode(wp_remote_retrieve_body($content));
248
249 return (!isset($content->content)) ? null : $content->content;
250 }
251
252 public static function abs_path_to_url( $path = '' ) {
253 $url = str_replace(
254 wp_normalize_path( untrailingslashit( ABSPATH ) ),
255 site_url(),
256 wp_normalize_path( $path )
257 );
258 return esc_url_raw( $url );
259 }
260
261 }