PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.4.0
EmailKit – Email Customizer for WooCommerce & WP v1.4.0
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.4.0, at includes/Admin/TemplateList.php

233 lines 9.2 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 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/1/preview-thumb.svg',
21 'demo-url' => 'https://wpmet.com/',
22 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/1/content.json',
23 ],
24 'template-2' => [
25 'id' => 2,
26 'package' => 'free',
27 'mail_type' => 'woocommerce',
28 'title' => EmailLists::CANCELLED_ORDER,
29 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/2/preview-thumb.svg',
30 'demo-url' => 'https://wpmet.com/',
31 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/2/content.json',
32
33 ],
34 'template-3' => [
35 'id' => 3,
36 'package' => 'free',
37 'mail_type' => 'woocommerce',
38 'title' => EmailLists::FAILED_ORDER,
39 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/3/preview-thumb.svg',
40 'demo-url' => 'https://wpmet.com/',
41 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/3/content.json',
42 ],
43 'template-4' => [
44 'id' => 4,
45 'package' => 'free',
46 'mail_type' => 'woocommerce',
47 'title' => EmailLists::ORDER_ON_HOLD,
48 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/4/preview-thumb.svg',
49 'demo-url' => 'https://wpmet.com/',
50 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/4/content.json',
51 ],
52 'template-5' => [
53 'id' => 5,
54 'package' => 'free',
55 'mail_type' => 'woocommerce',
56 'title' => EmailLists::PROCESSING_ORDER,
57 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/5/preview-thumb.svg',
58 'demo-url' => 'https://wpmet.com/',
59 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/5/content.json',
60 ],
61 'template-6' => [
62 'id' => 6,
63 'package' => 'free',
64 'mail_type' => 'woocommerce',
65 'title' => EmailLists::COMPLETED_ORDER,
66 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/6/preview-thumb.svg',
67 'demo-url' => 'https://wpmet.com/',
68 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/6/content.json'
69 ],
70 'template-7' => [
71 'id' => 7,
72 'package' => 'free',
73 'mail_type' => 'woocommerce',
74 'title' => EmailLists::REFUNDED_ORDER,
75 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/7/preview-thumb.svg',
76 'demo-url' => 'https://wpmet.com/',
77 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/7/content.json'
78 ],
79 'template-8' => [
80 'id' => 8,
81 'package' => 'free',
82 'mail_type' => 'woocommerce',
83 'title' => EmailLists::CUSTOMER_INVOICE_OR_ORDER_DETAILS,
84 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/8/preview-thumb.svg',
85 'demo-url' => 'https://products.wpmet.com/metform/job-listing-form/',
86 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/8/content.json'
87 ],
88 'template-9' => [
89 'id' => 9,
90 'package' => 'free',
91 'mail_type' => 'woocommerce',
92 'title' => EmailLists::CUSTOMER_NOTE,
93 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/9/preview-thumb.svg',
94 'demo-url' => 'https://wpmet.com/',
95 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/9/content.json'
96 ],
97 'template-10' => [
98 'id' => 10,
99 'package' => 'free',
100 'mail_type' => 'woocommerce',
101 'title' => EmailLists::NEW_ACCOUNT,
102 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/10/preview-thumb.svg',
103 'demo-url' => 'https://wpmet.com/',
104 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/10/content.json'
105 ],
106
107 'template-11' => [
108 'id' => 11,
109 'package' => 'free',
110 'mail_type' => 'woocommerce',
111 'title' => EmailLists::RESET_PASSWORD,
112 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/11/preview-thumb.svg',
113 'demo-url' => 'https://wpmet.com/',
114 'file' => self::EMAILKIT_URL_TEMAPLTE_DIR . 'templates/11/content.json'
115 ],
116 'template-12' => [
117 'id' => 12,
118 'package' => 'pro',
119 'mail_type' => 'woocommerce',
120 'title' => EmailLists::LOW_STOCK,
121 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/11/preview-thumb.svg',
122 'demo-url' => 'https://wpmet.com/',
123 'file' => ''
124 ],
125 'template-13' => [
126 'id' => 13,
127 'package' => 'pro',
128 'mail_type' => 'woocommerce',
129 'title' => EmailLists::NO_STOCK,
130 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/11/preview-thumb.svg',
131 'demo-url' => 'https://wpmet.com/',
132 'file' => ''
133 ],
134 'template-14' => [
135 'id' => 14,
136 'package' => 'pro',
137 'mail_type' => 'woocommerce',
138 'title' => EmailLists::BACK_ORDER,
139 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/11/preview-thumb.svg',
140 'demo-url' => 'https://wpmet.com/',
141 'file' => ''
142 ],
143
144 'template-101' => [
145 'id' => 101,
146 'package' => 'pro',
147 'mail_type' => 'wordpress',
148 'title' => EmailLists::WP_NEW_REGISTER,
149 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/blank/preview-thumb.svg',
150 'demo-url' => 'https://wpmet.com/',
151 'file' => '',
152 ],
153 'template-102' => [
154 'id' => 102,
155 'package' => 'pro',
156 'mail_type' => 'wordpress',
157 'title' => EmailLists::WP_RESET_PASSWORD,
158 'preview-thumb' => self::EMAILKIT_URL_TEMAPLTE_URL . 'templates/blank/preview-thumb.svg',
159 'demo-url' => 'https://wpmet.com/',
160 'file' => ''
161 ],
162
163
164 ];
165
166 return apply_filters( 'emailkit/editor/templates', $template_list );
167 }
168
169
170 public static function get(){
171
172 $email_types = [
173
174 'wordpress' => __('WordPress Email', 'emailkit'),
175 ];
176
177 // Include necessary WordPress files
178 // require_once ABSPATH . 'wp-admin/includes/plugin.php';
179 // require_once ABSPATH . 'wp-includes/class-wp.php'; // Adjust the path if necessary
180
181
182 if(is_plugin_active(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php')){
183 $email_types['woocommerce'] = __('Woocommerce email', 'emailkit');
184 }
185
186 return apply_filters('emailkit_email_types',$email_types);
187 }
188
189
190 /**
191 * Get template list by form type
192 *
193 * @param string $mail_type
194 * @return array
195 */
196 public function get_templates_by_mail_type( $mail_type ) {
197 $templates_list = [];
198
199 // array filter
200 $templates_list = array_filter( $this->get_templates(), function( $template ) use ( $mail_type ) {
201 if(isset($template['mail_type'])){
202 return $template['mail_type'] === $mail_type;
203 }
204
205 return true;
206 } );
207
208 return $templates_list;
209 }
210
211 public function get_template_contents($id){
212
213 if(!array_key_exists($id, $this->get_templates()) || !file_exists($this->get_templates()[$id]['file'])){
214 return null;
215 }
216
217 $template_file_url = self::abs_path_to_url($this->get_templates()[$id]['file']);
218 $content = wp_remote_get($template_file_url, ['sslverify' => false]);
219 $content = json_decode(wp_remote_retrieve_body($content));
220
221 return (!isset($content->content)) ? null : $content->content;
222 }
223
224 public static function abs_path_to_url( $path = '' ) {
225 $url = str_replace(
226 wp_normalize_path( untrailingslashit( ABSPATH ) ),
227 site_url(),
228 wp_normalize_path( $path )
229 );
230 return esc_url_raw( $url );
231 }
232
233 }