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 / Page / Settings.php

Settings.php in YayMail – WooCommerce Email Customizer 1.9.6, at includes/Page/Settings.php

418 lines 17.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Page;
4
5 use YayMail\Ajax;
6 use YayMail\Page\Source\CustomPostType;
7 use YayMail\Page\Source\DefaultElement;
8 use YayMail\Templates\Templates;
9
10 defined( 'ABSPATH' ) || exit;
11 /**
12 * Settings Page
13 */
14 class Settings {
15
16 protected static $instance = null;
17
18 public static function getInstance() {
19 if ( null == self::$instance ) {
20 self::$instance = new self();
21 self::$instance->doHooks();
22 }
23
24 return self::$instance;
25 }
26
27 private $pageId = null;
28 private $templateAccount;
29 private $emails = null;
30 public function doHooks() {
31 $this->templateAccount = array( 'customer_new_account', 'customer_new_account_activation', 'customer_reset_password' );
32
33 // Register Custom Post Type use Email Builder
34 add_action( 'init', array( $this, 'registerCustomPostType' ) );
35
36 // Register Menu
37 add_action( 'admin_menu', array( $this, 'settingsMenu' ) );
38
39 // Register Style & Script use for Menu Backend
40 add_action( 'admin_enqueue_scripts', array( $this, 'enqueueAdminScripts' ) );
41
42 add_filter( 'plugin_action_links_' . YAYMAIL_PLUGIN_BASENAME, array( $this, 'plugin_action_links' ) );
43
44 // free version
45 $optionNotice = get_option( 'yaymail_notice' );
46 if ( time() >= (int) $optionNotice ) {
47 add_action( 'admin_notices', array( $this, 'renderNotice' ) );
48 }
49
50 // Ajax display notive
51 add_action( 'wp_ajax_yaymail_notice', array( $this, 'yaymailNotice' ) );
52
53 // Add Woocommerce email setting columns
54 add_filter( 'woocommerce_email_setting_columns', array( $this, 'yaymail_email_setting_columns' ) );
55 add_action( 'woocommerce_email_setting_column_template', array( $this, 'column_template' ) );
56 //add_shortcode( 'yaymail_billing_shipping_address_content', array( $this, 'shortcodeCallBack' ) );
57 // Excute Ajax
58 Ajax::getInstance();
59 }
60 public function __construct() {}
61 public function shortcodeCallBack( $atts ) {
62 $billing_address = $atts['billing_address'];
63 $shipping_address = $atts['shipping_address'];
64 ob_start();
65 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-billing-shipping-address-content.php';
66 $order = $this->order;
67 include $path;
68 $html = ob_get_contents();
69 ob_end_clean();
70 return $html;
71 }
72
73 public function yaymail_email_setting_columns( $array ) {
74 // filter...
75 if ( isset( $array['actions'] ) ) {
76 unset( $array['actions'] );
77 return array_merge(
78 $array,
79 array(
80 'template' => '',
81 'actions' => '',
82 )
83 );
84 }
85
86 return $array;
87 }
88
89 public function column_template( $email ) {
90 $arrEmailDefault = array(
91 'new_order',
92 'cancelled_order',
93 'failed_order',
94 'customer_on_hold_order',
95 'customer_processing_order',
96 'customer_completed_order',
97 'customer_refunded_order',
98 'customer_invoice',
99 'customer_note',
100 'customer_reset_password',
101 'customer_new_account',
102 );
103
104 if ( in_array( $email->id, $arrEmailDefault ) ) {
105 echo '<td class="wc-email-settings-table-template">
106 <a class="button alignright" target="_blank" href="' . esc_attr( admin_url( 'admin.php?page=yaymail-settings' ) ) . '&template=' . esc_attr( $email->id ) . '">' . esc_html( __( 'Customize with YayMail', 'yaymail' ) ) . '</a></td>';
107 } else {
108 echo '<td class="wc-email-settings-table-template">
109 <a class="button alignright" target="_blank" href="https://yaycommerce.com/yaymail-woocommerce-email-customizer/">' . esc_html( __( 'Customize with YayMail (PRO)', 'yaymail' ) ) . '</a></td>';
110 }
111
112 }
113
114 public function renderNotice() {
115 if ( is_plugin_active( 'woocommerce-subscriptions/woocommerce-subscriptions.php' )
116 || is_plugin_active( 'woocommerce-shipment-tracking/woocommerce-shipment-tracking.php' )
117 || is_plugin_active( 'woocommerce-order-status-manager/woocommerce-order-status-manager.php' )
118 || is_plugin_active( 'woocommerce-admin-custom-order-fields/woocommerce-admin-custom-order-fields.php' )
119 || is_plugin_active( 'woo-advanced-shipment-tracking/woo-advanced-shipment-tracking.php' )
120 || is_plugin_active( 'yith-woocommerce-subscription-premium/init.php' )
121 || is_plugin_active( 'yith-woocommerce-subscription/init.php' )
122 ) {
123 ?>
124
125 <div id="yaymail-notice" class="notice-info notice is-dismissible">
126 <h4 style="color: #000"><?php esc_html_e( 'Please upgrade to YayMail Pro to customize emails with:', 'yaymail' ); ?></h4>
127 <ul style="list-style: inside;">
128 <?php
129 ob_start();
130 $path = YAYMAIL_PLUGIN_PATH . '/includes/Page/Source/DisplayNotice.php';
131 include $path;
132 ?>
133 </ul>
134 <p style="padding-left:0">
135 <a href="https://yaycommerce.com/yaymail-woocommerce-email-customizer/ " target="_blank" data="upgradenow" class="button button-primary" style="margin-right: 5px"><?php esc_html_e( 'Upgrade Now', 'yaymail' ); ?></a>
136 <a href="javascript:;" data="later" class="button yaymail-nothank" style="margin-right: 5px"><?php esc_html_e( 'No, thanks', 'yaymail' ); ?></a>
137 </p>
138 </div>
139 <?php
140 }
141 }
142
143
144 public function yaymailNotice() {
145 if ( isset( $_POST ) ) {
146 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : null;
147
148 if ( ! wp_verify_nonce( $nonce, 'yaymail_nonce' ) ) {
149 wp_send_json_error( array( 'status' => 'Wrong nonce validate!' ) );
150 exit();
151 }
152 update_option( 'yaymail_notice', time() + 7 * 60 * 60 * 24 ); // After 7 days show
153 wp_send_json_success();
154 }
155 wp_send_json_error( array( 'message' => 'Update fail!' ) );
156 }
157
158 public function plugin_action_links( $links ) {
159 $action_links = array(
160 'settings' => '<a href="' . admin_url( 'admin.php?page=yaymail-settings' ) . '" aria-label="' . esc_attr__( 'View WooCommerce Email Builder', 'yaymail' ) . '">' . esc_html__( 'Settings', 'yaymail' ) . '</a>',
161 );
162 $links[] = '<a target="_blank" href="https://yaycommerce.com/yaymail-woocommerce-email-customizer/" style="color: #43B854; font-weight: bold">' . __( 'Go Pro', 'yaymail' ) . '</a>';
163 return array_merge( $action_links, $links );
164 }
165
166 public function registerCustomPostType() {
167 $labels = array(
168 'name' => __( 'Email Template', 'yaymail' ),
169 'singular_name' => __( 'Email Template', 'yaymail' ),
170 'add_new' => __( 'Add New Email Template', 'yaymail' ),
171 'add_new_item' => __( 'Add a new Email Template', 'yaymail' ),
172 'edit_item' => __( 'Edit Email Template', 'yaymail' ),
173 'new_item' => __( 'New Email Template', 'yaymail' ),
174 'view_item' => __( 'View Email Template', 'yaymail' ),
175 'search_items' => __( 'Search Email Template', 'yaymail' ),
176 'not_found' => __( 'No Email Template found', 'yaymail' ),
177 'not_found_in_trash' => __( 'No Email Template currently trashed', 'yaymail' ),
178 'parent_item_colon' => '',
179 );
180 $capabilities = array();
181 $args = array(
182 'labels' => $labels,
183 'public' => true,
184 'publicly_queryable' => true,
185 'show_ui' => false,
186 'query_var' => true,
187 'rewrite' => true,
188 'capability_type' => 'yaymail_template',
189 'capabilities' => $capabilities,
190 'hierarchical' => false,
191 'menu_position' => null,
192 'supports' => array( 'title', 'author', 'thumbnail' ),
193 );
194 register_post_type( 'yaymail_template', $args );
195 }
196 public function settingsMenu() {
197 add_submenu_page( 'woocommerce', __( 'Email Builder Settings', 'yaymail' ), __( 'Email Customizer', 'yaymail' ), 'manage_options', $this->getPageId(), array( $this, 'settingsPage' ) );
198 }
199
200 public function nitWebPluginRegisterButtons( $buttons ) {
201 $buttons[] = 'table';
202 $buttons[] = 'searchreplace';
203 $buttons[] = 'visualblocks';
204 $buttons[] = 'code';
205 $buttons[] = 'insertdatetime';
206 $buttons[] = 'autolink';
207 $buttons[] = 'contextmenu';
208 $buttons[] = 'advlist';
209 return $buttons;
210 }
211
212 public function njtWebPluginRegisterPlugin( $plugin_array ) {
213 $plugin_array['table'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/table/plugin.min.js';
214 $plugin_array['searchreplace'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/searchreplace/plugin.min.js';
215 $plugin_array['visualblocks'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/visualblocks/plugin.min.js';
216 $plugin_array['code'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/code/plugin.min.js';
217 $plugin_array['insertdatetime'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/insertdatetime/plugin.min.js';
218 $plugin_array['autolink'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/autolink/plugin.min.js';
219 $plugin_array['contextmenu'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/contextmenu/plugin.min.js';
220 $plugin_array['advlist'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/advlist/plugin.min.js';
221 return $plugin_array;
222 }
223
224 public function settingsPage() {
225 // When load this page will not show adminbar
226 ?>
227 <style type="text/css">
228 #wpcontent, #footer {opacity: 0}
229 #adminmenuback, #adminmenuwrap { display: none !important; }
230 </style>
231 <script type="text/javascript" id="yaymail-onload">
232 jQuery(document).ready( function() {
233 jQuery('#adminmenuback, #adminmenuwrap').remove();
234 });
235 </script>
236 <?php
237 // add new buttons
238 add_filter( 'mce_buttons', array( $this, 'nitWebPluginRegisterButtons' ) );
239
240 // Load the TinyMCE plugin
241 add_filter( 'mce_external_plugins', array( $this, 'njtWebPluginRegisterPlugin' ) );
242 $viewPath = YAYMAIL_PLUGIN_PATH . 'views/pages/html-settings.php';
243 include_once $viewPath;
244 }
245
246 public function enqueueAdminScripts( $screenId ) {
247 if ( 'woocommerce_page_yaymail-settings' === $screenId ) {
248 // Get list template from Woo
249 $wc_emails = \WC_Emails::instance();
250 $this->emails = (array) $wc_emails::instance()->emails;
251
252 // Insert database all order template from Woo
253 $templateEmail = Templates::getInstance();
254 $templates = $templateEmail::getList();
255
256 foreach ( $templates as $key => $template ) {
257 if ( ! CustomPostType::postIDByTemplate( $key ) ) {
258 $arr = array(
259 'mess' => '',
260 'post_date' => current_time( 'Y-m-d H:i:s' ),
261 'post_type' => 'yaymail_template',
262 'post_status' => 'publish',
263 '_yaymail_template' => $key,
264 '_yaymail_html' => $template['html'],
265 '_email_backgroundColor_settings' => 'rgb(236, 236, 236)',
266 '_yaymail_elements' => json_decode( $template['elements'], true ),
267
268 );
269 $insert = CustomPostType::insert( $arr );
270 }
271 }
272
273 /*
274 @@@@ Enable Disable
275 @@@@ note: Note the default value section is required when displaying in vue
276 */
277
278 $settingDefaultEnableDisable = array(
279 'new_order' => 1,
280 'cancelled_order' => 1,
281 'failed_order' => 1,
282 'customer_on_hold_order' => 1,
283 'customer_processing_order' => 1,
284 'customer_completed_order' => 1,
285 'customer_refunded_order' => 1,
286 'customer_invoice' => 0,
287 'customer_note' => 0,
288 'customer_reset_password' => 0,
289 'customer_new_account' => 0,
290 );
291
292 $settingEnableDisables = ( CustomPostType::templateEnableDisable( false ) ) ? CustomPostType::templateEnableDisable( false ) : $settingDefaultEnableDisable;
293
294 foreach ( $this->emails as $key => $value ) {
295 if ( ! array_key_exists( $value->id, $settingEnableDisables ) ) {
296 $settingEnableDisables[ $value->id ] = '0';
297 }
298 }
299
300 $settingDefaultGenerals = array(
301 'payment' => 2,
302 'product_image' => 0,
303 'image_size' => 'thumbnail',
304 'image_width' => '30px',
305 'image_height' => '30px',
306 'product_sku' => 1,
307 'background_color_table_items' => '#e5e5e5',
308 'content_items_color' => '#636363',
309 'title_items_color' => '#96588a',
310 'container_width' => '605px',
311 'order_url' => '',
312 'custom_css' => '',
313 'enable_css_custom' => 'no',
314 'image_position' => 'Top',
315 );
316 $settingGenerals = get_option( 'yaymail_settings' ) ? get_option( 'yaymail_settings' ) : $settingDefaultGenerals;
317 foreach ( $settingDefaultEnableDisable as $keyDefaultEnableDisable => $settingDefaultEnableDisable ) {
318 if ( ! array_key_exists( $keyDefaultEnableDisable, $settingEnableDisables ) ) {
319 $settingEnableDisables[ $keyDefaultEnableDisable ] = $settingDefaultEnableDisable;
320 };
321 }
322 $settingEnableDisables['yaymail_direction'] = get_option( 'yaymail_direction' ) ? get_option( 'yaymail_direction' ) : 'ltr';
323 $settings['enableDisable'] = $settingEnableDisables;
324
325 /*
326 @@@@ General
327 @@@@ note: Note the default value section is required when displaying in vue
328 */
329
330 $settingGenerals = get_option( 'yaymail_settings' ) ? get_option( 'yaymail_settings' ) : $settingDefaultGenerals;
331 foreach ( $settingDefaultGenerals as $keyDefaultGeneral => $settingGeneral ) {
332 if ( ! array_key_exists( $keyDefaultGeneral, $settingGenerals ) ) {
333 $settingGenerals[ $keyDefaultGeneral ] = $settingDefaultGenerals[ $keyDefaultGeneral ];
334 };
335 }
336 $settings['general'] = $settingGenerals;
337
338 $scriptId = $this->getPageId();
339 $order = CustomPostType::getListOrders();
340 wp_enqueue_script( $scriptId, YAYMAIL_PLUGIN_URL . 'assets/dist/js/main.js', array( 'jquery' ), YAYMAIL_VERSION, true );
341 wp_enqueue_style( $scriptId, YAYMAIL_PLUGIN_URL . 'assets/dist/css/main.css', array(), YAYMAIL_VERSION );
342
343 // Css of ant
344 // wp_enqueue_style($scriptId . 'antd-css', YAYMAIL_PLUGIN_URL . 'assets/admin/css/antd.min.css');
345 // Css file app
346 // wp_enqueue_style($scriptId, YAYMAIL_PLUGIN_URL . 'assets/dist/css/main.css');
347 wp_enqueue_script( $scriptId . '-script', YAYMAIL_PLUGIN_URL . 'assets/admin/js/script.js', '', YAYMAIL_VERSION, true );
348 $yaymailSettings = get_option( 'yaymail_settings' );
349
350 // Load ACE Editor -Start
351 if ( isset( $yaymailSettings['enable_css_custom'] ) && 'yes' == $yaymailSettings['enable_css_custom'] ) {
352 wp_enqueue_script( $scriptId . 'ace-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/ace.js', '', YAYMAIL_VERSION, true );
353 wp_enqueue_script( $scriptId . 'ace1-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/ext-language_tools.js', '', YAYMAIL_VERSION, true );
354 wp_enqueue_script( $scriptId . 'ace2-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/mode-css.js', '', YAYMAIL_VERSION, true );
355 wp_enqueue_script( $scriptId . 'ace3-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/theme-merbivore_soft.js', '', YAYMAIL_VERSION, true );
356 wp_enqueue_script( $scriptId . 'ace4-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/worker-css.js', '', YAYMAIL_VERSION, true );
357 wp_enqueue_script( $scriptId . 'ace5-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/snippets/css.js ', '', YAYMAIL_VERSION, true );
358 } else {
359 wp_dequeue_script( $scriptId . 'ace-script' );
360 wp_dequeue_script( $scriptId . 'ace1-script' );
361 wp_dequeue_script( $scriptId . 'ace2-script' );
362 wp_dequeue_script( $scriptId . 'ace3-script' );
363 wp_dequeue_script( $scriptId . 'ace4-script' );
364 wp_dequeue_script( $scriptId . 'ace5-script' );
365 }
366 // Load ACE Editor -End
367 // Css for page admin of WordPress.
368 wp_enqueue_style( $scriptId . '-css', YAYMAIL_PLUGIN_URL . 'assets/admin/css/css.css', array(), YAYMAIL_VERSION );
369 $current_user = wp_get_current_user();
370 $default_email_test = false != get_user_meta( get_current_user_id(), 'yaymail_default_email_test', true ) ? get_user_meta( get_current_user_id(), 'yaymail_default_email_test', true ) : $current_user->user_email;
371 $element = new DefaultElement();
372 if ( isset( $_GET['template'] ) || ! empty( $_GET['template'] ) ) {
373 $req_template['id'] = sanitize_text_field( $_GET['template'] );
374 } else {
375 $req_template['id'] = 'new_order';
376 }
377 foreach ( $this->emails as $value ) {
378 if ( $value->id == $req_template['id'] ) {
379 $req_template['title'] = $value->title;
380 }
381 }
382 wp_localize_script(
383 $scriptId,
384 'yaymail_data',
385 array(
386 'orders' => $order,
387 'imgUrl' => YAYMAIL_PLUGIN_URL . 'assets/dist/images',
388 'nonce' => wp_create_nonce( 'email-nonce' ),
389 'defaultDataElement' => $element->defaultDataElement,
390 'home_url' => home_url(),
391 'settings' => $settings,
392 'admin_url' => get_admin_url(),
393 'yaymail_plugin_url' => YAYMAIL_PLUGIN_URL,
394 'wc_emails' => $this->emails,
395 'default_email_test' => $default_email_test,
396 'template' => $req_template,
397 )
398 );
399 }
400 wp_enqueue_script( 'yaymail-notice', YAYMAIL_PLUGIN_URL . 'assets/admin/js/notice.js', array( 'jquery' ), YAYMAIL_VERSION, false );
401 wp_localize_script(
402 'yaymail-notice',
403 'yaymail_notice',
404 array(
405 'admin_ajax' => admin_url( 'admin-ajax.php' ),
406 'nonce' => wp_create_nonce( 'yaymail_nonce' ),
407 )
408 );
409 }
410 public function getPageId() {
411 if ( null == $this->pageId ) {
412 $this->pageId = YAYMAIL_PREFIX . '-settings';
413 }
414
415 return $this->pageId;
416 }
417 }
418