PluginProbe
YayMail – WooCommerce Email Customizer / 2.1.5
YayMail – WooCommerce Email Customizer v2.1.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 / includes / Helper / ActivePlugin.php

ActivePlugin.php in YayMail – WooCommerce Email Customizer 2.1.5, at includes/Helper/ActivePlugin.php

214 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Helper;
4
5 use YayMail\Page\Source\CustomPostType;
6 use YayMail\Page\Source\DefaultElement;
7 use YayMail\Templates\Templates;
8
9 defined( 'ABSPATH' ) || exit;
10 /**
11 * Plugin activate/deactivate logic
12 */
13 class ActivePlugin {
14
15 protected static $instance = null;
16 public static function getInstance() {
17 if ( null == self::$instance ) {
18 self::$instance = new self();
19 }
20
21 return self::$instance;
22 }
23
24 private function __construct() {
25 if ( function_exists( 'WC' ) ) {
26 $this->activePlugin();
27 }
28 $this->addDefaultSetting();
29 }
30
31 public function activePlugin() {
32 $templateEmail = Templates::getInstance();
33 $templates = $templateEmail::getList();
34
35 foreach ( $templates as $key => $template ) {
36 if ( ! CustomPostType::postIDByTemplate( $key ) ) {
37 $arr = array(
38 'mess' => '',
39 'post_date' => current_time( 'Y-m-d H:i:s' ),
40 'post_type' => 'yaymail_template',
41 'post_status' => 'publish',
42 '_yaymail_template' => $key,
43 '_email_backgroundColor_settings' => 'rgb(236, 236, 236)',
44 '_yaymail_elements' => json_decode( $template['elements'], true ),
45 '_yaymail_email_textLinkColor_settings' => '#96588A',
46 '_yaymail_email_order_item_title' => array(
47 'order_title' => '',
48 'product_title' => 'Product',
49 'quantity_title' => 'Quantity',
50 'price_title' => 'Price',
51 'subtoltal_title' => 'Subtotal:',
52 'payment_method_title' => 'Payment method:',
53 'total_title' => 'Total:',
54 'subscript_id' => 'ID',
55 'subscript_start_date' => 'Start date',
56 'subscript_end_date' => 'End date',
57 'subscript_recurring_total' => 'Recurring total',
58 'subscript_subscription' => 'Subscription',
59 'subscript_price' => 'Price',
60 'subscript_last_order_date' => 'Last Order Date',
61 'subscript_end_of_prepaid_term' => 'End of Prepaid Term',
62 'subscript_date_suspended' => 'Date Suspended',
63 ),
64 );
65 $insert = CustomPostType::insert( $arr );
66 } else {
67 if ( ! metadata_exists( 'post', CustomPostType::postIDByTemplate( $key ), '_yaymail_email_textLinkColor_settings' ) ) {
68 update_post_meta( CustomPostType::postIDByTemplate( $key ), '_yaymail_email_textLinkColor_settings', '#96588A' );
69 }
70
71 if ( ! metadata_exists( 'post', CustomPostType::postIDByTemplate( $key ), '_yaymail_email_order_item_title' ) ) {
72 $orderTitle = array(
73 'order_title' => '',
74 'product_title' => 'Product',
75 'quantity_title' => 'Quantity',
76 'price_title' => 'Price',
77 'subtoltal_title' => 'Subtotal:',
78 'payment_method_title' => 'Payment method:',
79 'total_title' => 'Total:',
80 'subscript_id' => 'ID',
81 'subscript_start_date' => 'Start date',
82 'subscript_end_date' => 'End date',
83 'subscript_recurring_total' => 'Recurring total',
84 'subscript_subscription' => 'Subscription',
85 'subscript_price' => 'Price',
86 'subscript_last_order_date' => 'Last Order Date',
87 'subscript_end_of_prepaid_term' => 'End of Prepaid Term',
88 'subscript_date_suspended' => 'Date Suspended',
89 );
90
91 update_post_meta( CustomPostType::postIDByTemplate( $key ), '_yaymail_email_order_item_title', $orderTitle );
92 }
93 }
94 }
95
96 if ( ! get_option( 'yaymail_version' ) ) {
97 update_option( 'yaymail_version', YAYMAIL_VERSION );
98 }
99 if ( ! get_option( 'yaymail_direction' ) ) {
100 update_option( 'yaymail_direction', 'ltr' );
101 }
102
103 /*
104 @@@@check key in settingRow whether or not it exists.
105 @@@@note: case when add setting row for element.
106 */
107 $versionCurrent = YAYMAIL_VERSION;
108 $versionOld = get_option( 'yaymail_version' );
109
110 if ( $versionCurrent != $versionOld ) {
111 $posts = CustomPostType::getListPostTemplate();
112 if ( count( $posts ) > 0 ) {
113 foreach ( $posts as $post ) {
114 $elements = get_post_meta( $post->ID, '_yaymail_elements', true );
115
116 $defaultElement = new DefaultElement();
117 $defaultDataElements = $defaultElement->defaultDataElement;
118
119 foreach ( $defaultDataElements as $defaultelement ) {
120
121 foreach ( $elements as $keyEl => $element ) {
122
123 if ( $defaultelement['type'] == $element['type'] ) {
124 /*
125 @@@ add key default for element
126 */
127 $keyEleDefaus = array();
128 $keyEleDefaus = array_diff_key( $defaultelement, $element );
129 if ( count( $keyEleDefaus ) > 0 ) {
130 $elements[ $keyEl ] = array_merge( $element, $keyEleDefaus );
131 }
132
133 /*
134 @@@ add key default for setting row.
135 @@@ note: when add a field in setting row
136 */
137 $propSettings = array();
138 $propSettings = array_diff_key( $defaultelement['settingRow'], $element['settingRow'] );
139 $lenPropSettings = count( $propSettings );
140 if ( $lenPropSettings > 0 ) {
141 $result = array();
142 $result = array_merge( $element['settingRow'], $propSettings );
143 $elements[ $keyEl ]['settingRow'] = $result;
144 }
145
146 /*
147 @@@ remove Key not needed for setting row
148 @@@ note: when deleting a field in setting row
149 */
150 // $propSetNotNeeds= array();
151 // $propSetNotNeeds = array_diff_key($element['settingRow'], $defaultelement['settingRow']);
152 // $lenpropSetNotNeeds = count($propSetNotNeeds);
153 // if($lenpropSetNotNeeds > 0) {
154 // foreach($propSetNotNeeds as $keyNotNeed => $propSetNotNeed) {
155 // unset($elements[$keyEl]['settingRow'][$keyNotNeed]);
156 // }
157 // }
158 }
159 }
160 }
161 update_post_meta( $post->ID, '_yaymail_elements', $elements );
162 }
163 }
164 }
165
166 $settingDefault = CustomPostType::templateEnableDisable();
167 $listTemplates = ! empty( $settingDefault ) ? array_keys( $settingDefault ) : array();
168 $settingCurrent = array(
169 'new_order' => 1,
170 'cancelled_order' => 1,
171 'failed_order' => 1,
172 'customer_on_hold_order' => 1,
173 'customer_processing_order' => 1,
174 'customer_completed_order' => 1,
175 'customer_refunded_order' => 1,
176 'customer_invoice' => 0,
177 'customer_note' => 0,
178 'customer_reset_password' => 0,
179 'customer_new_account' => 0,
180 );
181
182 if ( ! empty( $listTemplates ) ) {
183 foreach ( $settingCurrent as $key => $value ) {
184 if ( in_array( $key, $listTemplates )
185 && ! metadata_exists( 'post', $settingDefault[ $key ]['post_id'], '_yaymail_status' )
186 ) {
187 update_post_meta( $settingDefault[ $key ]['post_id'], '_yaymail_status', $value );
188 }
189 }
190 }
191 }
192 public function addDefaultSetting() {
193 if ( ! get_option( 'yaymail_settings' ) ) {
194 $settings = array(
195 'payment' => 2,
196 'product_image' => 0,
197 'image_size' => 'thumbnail',
198 'image_width' => '30px',
199 'image_height' => '30px',
200 'product_sku' => 1,
201 'background_color_table_items' => '#e5e5e5',
202 'content_items_color' => '#636363',
203 'title_items_color' => '#96588a',
204 'container_width' => '605px',
205 'order_url' => '',
206 'custom_css' => '',
207 'enable_css_custom' => 'no',
208 'direction_rtl' => 'ltr',
209 );
210 update_option( 'yaymail_settings', $settings );
211 }
212 }
213 }
214