PluginProbe
YayMail – WooCommerce Email Customizer / 1.9.6
YayMail – WooCommerce Email Customizer v1.9.6
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 1.9.6, at includes/Helper/ActivePlugin.php

194 lines 6.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 }
29
30 public function activePlugin() {
31 $templateEmail = Templates::getInstance();
32 $templates = $templateEmail::getList();
33
34 foreach ( $templates as $key => $template ) {
35 if ( ! CustomPostType::postIDByTemplate( $key ) ) {
36 $arr = array(
37 'mess' => '',
38 'post_date' => current_time( 'Y-m-d H:i:s' ),
39 'post_type' => 'yaymail_template',
40 'post_status' => 'publish',
41 '_yaymail_template' => $key,
42 '_yaymail_html' => $template['html'],
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 ),
55 );
56 $insert = CustomPostType::insert( $arr );
57 } else {
58 if ( ! metadata_exists( 'post', CustomPostType::postIDByTemplate( $key ), '_yaymail_email_textLinkColor_settings' ) ) {
59 update_post_meta( CustomPostType::postIDByTemplate( $key ), '_yaymail_email_textLinkColor_settings', '#96588A' );
60 }
61
62 if ( ! metadata_exists( 'post', CustomPostType::postIDByTemplate( $key ), '_yaymail_email_order_item_title' ) ) {
63 $orderTitle = array(
64 'order_title' => '',
65 'product_title' => 'Product',
66 'quantity_title' => 'Quantity',
67 'price_title' => 'Price',
68 'subtoltal_title' => 'Subtotal:',
69 'payment_method_title' => 'Payment method:',
70 'total_title' => 'Total:',
71 );
72
73 update_post_meta( CustomPostType::postIDByTemplate( $key ), '_yaymail_email_order_item_title', $orderTitle );
74 }
75 }
76 }
77
78 if ( ! get_option( 'yaymail_version' ) ) {
79 update_option( 'yaymail_version', YAYMAIL_VERSION );
80 }
81 if ( ! get_option( 'yaymail_direction' ) ) {
82 update_option( 'yaymail_direction', 'ltr' );
83 }
84
85 /*
86 @@@@check key in settingRow whether or not it exists.
87 @@@@note: case when add setting row for element.
88 */
89 $versionCurrent = YAYMAIL_VERSION;
90 $versionOld = get_option( 'yaymail_version' );
91
92 if ( $versionCurrent != $versionOld ) {
93 $posts = CustomPostType::getListPostTemplate();
94 if ( count( $posts ) > 0 ) {
95 foreach ( $posts as $post ) {
96 $elements = get_post_meta( $post->ID, '_yaymail_elements', true );
97
98 $defaultElement = new DefaultElement();
99 $defaultDataElements = $defaultElement->defaultDataElement;
100
101 foreach ( $defaultDataElements as $defaultelement ) {
102
103 foreach ( $elements as $keyEl => $element ) {
104
105 if ( $defaultelement['type'] == $element['type'] ) {
106 /*
107 @@@ add key default for element
108 */
109 $keyEleDefaus = array();
110 $keyEleDefaus = array_diff_key( $defaultelement, $element );
111 if ( count( $keyEleDefaus ) > 0 ) {
112 $elements[ $keyEl ] = array_merge( $element, $keyEleDefaus );
113 }
114
115 /*
116 @@@ add key default for setting row.
117 @@@ note: when add a field in setting row
118 */
119 $propSettings = array();
120 $propSettings = array_diff_key( $defaultelement['settingRow'], $element['settingRow'] );
121 $lenPropSettings = count( $propSettings );
122 if ( $lenPropSettings > 0 ) {
123 $result = array();
124 $result = array_merge( $element['settingRow'], $propSettings );
125 $elements[ $keyEl ]['settingRow'] = $result;
126 }
127
128 /*
129 @@@ remove Key not needed for setting row
130 @@@ note: when deleting a field in setting row
131 */
132 // $propSetNotNeeds= array();
133 // $propSetNotNeeds = array_diff_key($element['settingRow'], $defaultelement['settingRow']);
134 // $lenpropSetNotNeeds = count($propSetNotNeeds);
135 // if($lenpropSetNotNeeds > 0) {
136 // foreach($propSetNotNeeds as $keyNotNeed => $propSetNotNeed) {
137 // unset($elements[$keyEl]['settingRow'][$keyNotNeed]);
138 // }
139 // }
140 }
141 }
142 }
143 update_post_meta( $post->ID, '_yaymail_elements', $elements );
144 }
145 }
146 }
147
148 $settingDefault = CustomPostType::templateEnableDisable();
149 $listTemplates = ! empty( $settingDefault ) ? array_keys( $settingDefault ) : array();
150 $settingCurrent = array(
151 'new_order' => 1,
152 'cancelled_order' => 1,
153 'failed_order' => 1,
154 'customer_on_hold_order' => 1,
155 'customer_processing_order' => 1,
156 'customer_completed_order' => 1,
157 'customer_refunded_order' => 1,
158 'customer_invoice' => 0,
159 'customer_note' => 0,
160 'customer_reset_password' => 0,
161 'customer_new_account' => 0,
162 );
163
164 if ( ! empty( $listTemplates ) ) {
165 foreach ( $settingCurrent as $key => $value ) {
166 if ( in_array( $key, $listTemplates )
167 && ! metadata_exists( 'post', $settingDefault[ $key ]['post_id'], '_yaymail_status' )
168 ) {
169 update_post_meta( $settingDefault[ $key ]['post_id'], '_yaymail_status', $value );
170 }
171 }
172 }
173
174 if ( ! get_option( 'yaymail_settings' ) ) {
175 $settings = array(
176 'payment' => 2,
177 'product_image' => 0,
178 'image_size' => 'thumbnail',
179 'image_width' => '30px',
180 'image_height' => '30px',
181 'product_sku' => 1,
182 'background_color_table_items' => '#e5e5e5',
183 'content_items_color' => '#636363',
184 'title_items_color' => '#96588a',
185 'container_width' => '605px',
186 'order_url' => '',
187 'custom_css' => '',
188 'enable_css_custom' => 'no',
189 );
190 update_option( 'yaymail_settings', $settings );
191 }
192 }
193 }
194