PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.6.0
EmailKit – Email Customizer for WooCommerce & WP v1.6.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 / Emails / EmailLists.php

EmailLists.php in EmailKit – Email Customizer for WooCommerce & WP 1.6.0, at includes/Admin/Emails/EmailLists.php

173 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Emailkit\Admin\Emails;
3
4 defined( "ABSPATH") || exit;
5
6 class EmailLists {
7 const NEW_ORDER = "new_order";
8 const CANCELLED_ORDER = "cancelled_order";
9 const FAILED_ORDER = "failed_order";
10 const FAILED_ORDER_CUSTOMER = "customer_failed_order";
11 const ORDER_ON_HOLD = "customer_on_hold_order";
12 const PROCESSING_ORDER = "customer_processing_order";
13 const COMPLETED_ORDER = "customer_completed_order";
14 const REFUNDED_ORDER = "customer_refunded_order";
15 const LOW_STOCK = "low_stock";
16 const NO_STOCK = "no_stock";
17 const BACK_ORDER = "back_order";
18 const CUSTOMER_INVOICE_OR_ORDER_DETAILS = "customer_invoice";
19 // const ORDER_DETAILS = "Order Details";
20 const CUSTOMER_NOTE = "customer_note";
21 const RESET_PASSWORD = "customer_reset_password";
22 const NEW_ACCOUNT = "customer_new_account";
23 const WP_NEW_REGISTER = "new_register";
24 const WP_RESET_PASSWORD = "reset_account";
25 const PARTIAL_REFUND = "partial_refund";
26 const METFORM = "metform";
27
28
29 /**
30 * Get woocommerce template names
31 * @return array
32 */
33 public static function woocommerce_email($template_type = '') {
34 $list = [
35 'Select Template' => esc_html__('Select Template', 'emailkit'),
36 self::NEW_ORDER => esc_html__('New Order', 'emailkit'),
37 self::CANCELLED_ORDER => esc_html__('Cancelled order', 'emailkit'),
38 self::FAILED_ORDER => esc_html__('Failed Order - Admin', 'emailkit'),
39 self::FAILED_ORDER_CUSTOMER => esc_html__('Failed Order - Customer', 'emailkit'),
40 self::ORDER_ON_HOLD => esc_html__('Order On Hold', 'emailkit'),
41 self::PROCESSING_ORDER => esc_html__('Processing Order', 'emailkit'),
42 self::COMPLETED_ORDER => esc_html__('Completed Order', 'emailkit'),
43 self::LOW_STOCK => esc_html__('Low Stock', 'emailkit'),
44 self::NO_STOCK => esc_html__('No Stock', 'emailkit'),
45 self::BACK_ORDER => esc_html__('Back Order', 'emailkit'),
46 self::REFUNDED_ORDER => esc_html__('Refunded Order', 'emailkit'),
47 self::PARTIAL_REFUND => esc_html__('Partial Refund', 'emailkit'),
48 self::CUSTOMER_INVOICE_OR_ORDER_DETAILS => esc_html__('Customer Invoice ', 'emailkit'),
49 self::CUSTOMER_NOTE => esc_html__('Customer Note', 'emailkit'),
50 self::NEW_ACCOUNT => esc_html__('New Account', 'emailkit'),
51 self::RESET_PASSWORD => esc_html__('Reset Password', 'emailkit'),
52 ];
53
54 if($template_type){
55 return isset($list[$template_type]) ? $list[$template_type] : '';
56 }
57
58 return $list;
59 }
60
61 /**
62 * Get wordpress template names
63 * @return array
64 */
65 public static function wordpress_email($template_type = '') {
66 $list = [
67 'Select Template' => esc_html__('Select Template', 'emailkit'),
68 self::WP_NEW_REGISTER => esc_html__('New Account', 'emailkit'),
69 self::WP_RESET_PASSWORD => esc_html__('Reset Password', 'emailkit'),
70 ];
71
72 if ($template_type) {
73 return isset($list[$template_type]) ? $list[$template_type] : '';
74 }
75
76 return $list;
77 }
78
79 public static function metform_email($template_type = '') {
80 $list = ['Select Template' => esc_html__('Select Form', 'emailkit')];
81
82 $metform_forms = get_posts([
83 'post_type' => 'metform-form',
84 'post_status' => 'publish',
85 'numberposts' => -1,
86 'orderby' => 'title',
87 'order' => 'ASC',
88 ]);
89
90 // Free: Check for templates
91 $templates = get_posts([
92 'post_type' => 'emailkit',
93 'meta_query' => [['key' => 'emailkit_template_type', 'value' => 'metform_form_', 'compare' => 'LIKE']],
94 'posts_per_page' => 1,
95 'fields' => 'ids',
96 'orderby' => 'ID',
97 'order' => 'ASC'
98 ]);
99
100 if (defined('EMAILKITPRO_VERSION') || class_exists('EmailKitPro')) {
101 // Pro: Show all forms
102 foreach ($metform_forms as $form) {
103 $list['metform_form_' . $form->ID] = esc_html__('Form: ', 'emailkit') . $form->post_title;
104 }
105 } else {
106 if (empty($templates)) {
107 // No templates: Show all forms
108 foreach ($metform_forms as $form) {
109 $list['metform_form_' . $form->ID] = esc_html__('Form: ', 'emailkit') . $form->post_title;
110 }
111 } else {
112 // Templates exist: Show only forms with templates
113 $form_ids = [];
114 foreach ($templates as $template_id) {
115 $form_id = get_post_meta($template_id, 'emailkit_form_id', true) ?:
116 (preg_match('/metform_form_(\d+)/', get_post_meta($template_id, 'emailkit_template_type', true), $matches) ? $matches[1] : 0);
117 if ($form_id) $form_ids[] = (int) $form_id;
118 }
119 foreach ($metform_forms as $form) {
120 if (in_array($form->ID, $form_ids)) {
121 $list['metform_form_' . $form->ID] = esc_html__('Form: ', 'emailkit') . $form->post_title;
122 }
123 }
124 }
125 }
126
127 if( !class_exists( 'EmailKitPro' ) && is_array($metform_forms) && count($metform_forms) > 1 && !empty($templates)) {
128
129 $list['more-forms'] = esc_html__( 'More Forms...', 'emailkit' );
130 }
131
132 return $template_type ? ($list[$template_type] ?? '') : $list;
133 }
134
135 /**
136 * Get saved templates from database
137 * @return array
138 */
139 public static function saved_templates() : array {
140
141 $emailkit_saved_templates = [];
142
143 $templates = get_posts([
144 'post_type' => 'emailkit-template',
145 'numberposts' => -1,
146 ]);
147
148
149 foreach ( $templates as $template ) {
150
151 setup_postdata( $template );
152
153 $template_id = get_post_meta( $template->ID, 'emailkit_template_id', true ); //get the id of main template to fetch types and etc
154
155 $emailkit_saved_templates[] = array(
156 'title' => $template->post_title,
157 'id' => $template->ID,
158 'template_id' => $template_id,
159 'email_type' => get_post_meta( $template_id, 'emailkit_email_type', true ),
160 'template_type' => get_post_meta( $template_id, 'emailkit_template_type', true ),
161 'template_status' => get_post_meta( $template_id, 'emailkit_template_status', true ),
162 );
163
164 }
165
166 wp_reset_postdata();
167
168
169 return $emailkit_saved_templates;
170 }
171
172
173 }