PluginProbe
YayMail – WooCommerce Email Customizer / 3.2.2
YayMail – WooCommerce Email Customizer v3.2.2
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 3.4.2 3.4.3 All 55 releases
yaymail / includes / Helper / ActivePlugin.php

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

184 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 use YayMail\Helper\Helper;
9
10 defined( 'ABSPATH' ) || exit;
11 /**
12 * Plugin activate/deactivate logic
13 */
14 class ActivePlugin {
15
16 protected static $instance = null;
17 public static function getInstance() {
18 if ( null == self::$instance ) {
19 self::$instance = new self();
20 }
21
22 return self::$instance;
23 }
24
25 private function __construct() {
26 if ( function_exists( 'WC' ) ) {
27 $this->activePlugin();
28 }
29 $this->addDefaultSetting();
30 }
31
32 public function activePlugin() {
33 $templateEmail = Templates::getInstance();
34 $templates = $templateEmail::getList();
35 $orderItemsTitle = Helper::OrderItemsTitle();
36 $orderItemsDownloadsTitle = Helper::OrderItemsDownloadsTitle();
37
38 foreach ( $templates as $key => $template ) {
39 if ( ! CustomPostType::postIDByTemplate( $key ) ) {
40 $arr = array(
41 'mess' => '',
42 'post_date' => current_time( 'Y-m-d H:i:s' ),
43 'post_type' => 'yaymail_template',
44 'post_status' => 'publish',
45 '_yaymail_template' => $key,
46 '_email_backgroundColor_settings' => 'rgb(236, 236, 236)',
47 '_yaymail_elements' => json_decode( $template['elements'], true ),
48 '_yaymail_email_textLinkColor_settings' => '#7f54b3',
49 '_yaymail_email_order_item_title' => $orderItemsTitle,
50 '_yaymail_email_order_item_download_title' => $orderItemsDownloadsTitle,
51 );
52 $insert = CustomPostType::insert( $arr );
53 } else {
54 if ( ! metadata_exists( 'post', CustomPostType::postIDByTemplate( $key ), '_yaymail_email_textLinkColor_settings' ) ) {
55 update_post_meta( CustomPostType::postIDByTemplate( $key ), '_yaymail_email_textLinkColor_settings', '#7f54b3' );
56 }
57 if ( ! metadata_exists( 'post', CustomPostType::postIDByTemplate( $key ), '_yaymail_email_order_item_title' ) ) {
58 update_post_meta( CustomPostType::postIDByTemplate( $key ), '_yaymail_email_order_item_title', $orderItemsTitle );
59 } else {
60 $yaymail_email_order_item_title = get_post_meta( $key, '_yaymail_email_order_item_title', true );
61 $merge_yaymail_email_order_item_title = array_merge( $orderItemsTitle, $yaymail_email_order_item_title );
62 update_post_meta( $key, '_yaymail_email_order_item_title', $merge_yaymail_email_order_item_title );
63 }
64 if ( ! metadata_exists( 'post', CustomPostType::postIDByTemplate( $key ), '_yaymail_email_order_item_download_title' ) ) {
65 update_post_meta( CustomPostType::postIDByTemplate( $key ), '_yaymail_email_order_item_download_title', $orderItemsDownloadsTitle );
66 }
67 }
68 }
69
70 if ( ! get_option( 'yaymail_version' ) ) {
71 update_option( 'yaymail_version', YAYMAIL_VERSION );
72 }
73 if ( ! get_option( 'yaymail_direction' ) ) {
74 update_option( 'yaymail_direction', 'ltr' );
75 }
76
77 /*
78 @@@@check key in settingRow whether or not it exists.
79 @@@@note: case when add setting row for element.
80 */
81 $versionCurrent = YAYMAIL_VERSION;
82 $versionOld = get_option( 'yaymail_version' );
83
84 if ( $versionCurrent != $versionOld ) {
85 update_option( 'yaymail_version', YAYMAIL_VERSION );
86 $posts = CustomPostType::getListPostTemplate();
87 if ( count( $posts ) > 0 ) {
88 foreach ( $posts as $post ) {
89 $elements = get_post_meta( $post->ID, '_yaymail_elements', true );
90
91 $defaultElement = new DefaultElement();
92 $defaultDataElements = $defaultElement->defaultDataElement;
93
94 foreach ( $defaultDataElements as $defaultelement ) {
95
96 foreach ( $elements as $keyEl => $element ) {
97
98 if ( $defaultelement['type'] == $element['type'] ) {
99 /*
100 @@@ add key default for element
101 */
102 $keyEleDefaus = array();
103 $keyEleDefaus = array_diff_key( $defaultelement, $element );
104 if ( count( $keyEleDefaus ) > 0 ) {
105 $elements[ $keyEl ] = array_merge( $element, $keyEleDefaus );
106 }
107
108 /*
109 @@@ add key default for setting row.
110 @@@ note: when add a field in setting row
111 */
112 $propSettings = array();
113 $propSettings = array_diff_key( $defaultelement['settingRow'], $element['settingRow'] );
114 $lenPropSettings = count( $propSettings );
115 if ( $lenPropSettings > 0 ) {
116 $result = array();
117 $result = array_merge( $element['settingRow'], $propSettings );
118 $elements[ $keyEl ]['settingRow'] = $result;
119 }
120 }
121 }
122 }
123 update_post_meta( $post->ID, '_yaymail_elements', $elements );
124 }
125 }
126 }
127
128 $settingDefault = CustomPostType::templateEnableDisable();
129 $listTemplates = ! empty( $settingDefault ) ? array_keys( $settingDefault ) : array();
130 $settingCurrent = array(
131 'new_order' => 1,
132 'cancelled_order' => 1,
133 'failed_order' => 1,
134 'customer_on_hold_order' => 1,
135 'customer_processing_order' => 1,
136 'customer_completed_order' => 1,
137 'customer_refunded_order' => 1,
138 'customer_invoice' => 0,
139 'customer_note' => 0,
140 'customer_reset_password' => 0,
141 'customer_new_account' => 0,
142 );
143
144 if ( ! empty( $listTemplates ) ) {
145 foreach ( $settingCurrent as $key => $value ) {
146 if ( in_array( $key, $listTemplates )
147 && ! metadata_exists( 'post', $settingDefault[ $key ]['post_id'], '_yaymail_status' )
148 ) {
149 update_post_meta( $settingDefault[ $key ]['post_id'], '_yaymail_status', $value );
150 }
151 }
152 }
153 }
154 public function addDefaultSetting() {
155 $settings_default = array(
156 'payment' => 2,
157 'product_image' => 0,
158 'image_size' => 'thumbnail',
159 'image_width' => '30px',
160 'image_height' => '30px',
161 'product_sku' => 1,
162 'product_des' => 0,
163 'product_hyper_links' => 0,
164 'product_regular_price' => 0,
165 'product_item_cost' => 0,
166 'background_color_table_items' => '#e5e5e5',
167 'content_items_color' => '#636363',
168 'title_items_color' => '#7f54b3',
169 'container_width' => '605px',
170 'order_url' => '',
171 'custom_css' => '',
172 'enable_css_custom' => 'no',
173 'direction_rtl' => 'ltr',
174 );
175 if ( ! get_option( 'yaymail_settings' ) ) {
176 update_option( 'yaymail_settings', $settings_default );
177 } else {
178 $yaymail_settings_option = get_option( 'yaymail_settings' );
179 $merge_yaymail_settings_option = array_merge( $settings_default, $yaymail_settings_option );
180 update_option( 'yaymail_settings', $merge_yaymail_settings_option );
181 }
182 }
183 }
184