| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMail\Page; |
| 4 |
|
| 5 |
use stdClass; |
| 6 |
use YayMail\Ajax; |
| 7 |
use YayMail\Page\Source\CustomPostType; |
| 8 |
use YayMail\Page\Source\DefaultElement; |
| 9 |
use YayMail\Templates\Templates; |
| 10 |
use YayMail\I18n; |
| 11 |
use YayMail\Helper\Helper; |
| 12 |
use YayMail\Helper\PluginSupported; |
| 13 |
|
| 14 |
|
| 15 |
defined( 'ABSPATH' ) || exit; |
| 16 |
/** |
| 17 |
* Settings Page |
| 18 |
*/ |
| 19 |
class Settings { |
| 20 |
|
| 21 |
protected static $instance = null; |
| 22 |
|
| 23 |
public static function getInstance() { |
| 24 |
if ( null == self::$instance ) { |
| 25 |
self::$instance = new self(); |
| 26 |
self::$instance->doHooks(); |
| 27 |
} |
| 28 |
|
| 29 |
return self::$instance; |
| 30 |
} |
| 31 |
|
| 32 |
private $pageId = null; |
| 33 |
private $templateAccount; |
| 34 |
private $emails = null; |
| 35 |
public function doHooks() { |
| 36 |
$this->templateAccount = array( 'customer_new_account', 'customer_new_account_activation', 'customer_reset_password' ); |
| 37 |
|
| 38 |
// Register Custom Post Type use Email Builder |
| 39 |
add_action( 'init', array( $this, 'registerCustomPostType' ) ); |
| 40 |
|
| 41 |
// Register Menu |
| 42 |
add_action( 'admin_menu', array( $this, 'settingsMenu' ), YAYMAIL_MENU_PRIORITY ); |
| 43 |
|
| 44 |
// Register Style & Script use for Menu Backend |
| 45 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueueAdminScripts' ) ); |
| 46 |
|
| 47 |
add_filter( 'plugin_action_links_' . YAYMAIL_PLUGIN_BASENAME, array( $this, 'plugin_action_links' ) ); |
| 48 |
|
| 49 |
add_filter( 'plugin_row_meta', array( $this, 'add_support_and_docs_links' ), 10, 2 ); |
| 50 |
|
| 51 |
// free version |
| 52 |
$optionNotice = get_option( 'yaymail_notice' ); |
| 53 |
if ( time() >= (int) $optionNotice ) { |
| 54 |
add_action( 'admin_notices', array( $this, 'renderNotice' ) ); |
| 55 |
} |
| 56 |
|
| 57 |
// Ajax display notive |
| 58 |
add_action( 'wp_ajax_yaymail_notice', array( $this, 'yaymailNotice' ) ); |
| 59 |
|
| 60 |
// Add Woocommerce email setting columns |
| 61 |
add_filter( 'woocommerce_email_setting_columns', array( $this, 'yaymail_email_setting_columns' ) ); |
| 62 |
add_action( 'woocommerce_email_setting_column_template', array( $this, 'column_template' ) ); |
| 63 |
|
| 64 |
// Add WP_Query argument to search either by post_title or meta_value |
| 65 |
add_action( |
| 66 |
'pre_get_posts', |
| 67 |
array( $this, 'search_by_meta_value_or_post_title' ) |
| 68 |
); |
| 69 |
|
| 70 |
// Excute Ajax |
| 71 |
Ajax::getInstance(); |
| 72 |
} |
| 73 |
public function __construct() {} |
| 74 |
|
| 75 |
public function yaymail_email_setting_columns( $array ) { |
| 76 |
if ( isset( $array['actions'] ) ) { |
| 77 |
unset( $array['actions'] ); |
| 78 |
return array_merge( |
| 79 |
$array, |
| 80 |
array( |
| 81 |
'template' => '', |
| 82 |
'actions' => '', |
| 83 |
) |
| 84 |
); |
| 85 |
} |
| 86 |
return $array; |
| 87 |
} |
| 88 |
public function column_template( $email ) { |
| 89 |
$email_id = $email->id; |
| 90 |
if ( 'yith-coupon-email-system' === $email->id ) { |
| 91 |
if ( class_exists( 'YayMailYITHWooCouponEmailSystem\templateDefault\DefaultCouponEmailSystem' ) ) { |
| 92 |
$email_id = 'YWCES_register'; |
| 93 |
} |
| 94 |
} |
| 95 |
echo '<td class="wc-email-settings-table-template"> |
| 96 |
<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>'; |
| 97 |
} |
| 98 |
|
| 99 |
public function renderNotice() { |
| 100 |
|
| 101 |
include YAYMAIL_PLUGIN_PATH . '/includes/Page/Source/DisplayAddonNotice.php'; |
| 102 |
} |
| 103 |
|
| 104 |
public function yaymailNotice() { |
| 105 |
if ( isset( $_POST ) ) { |
| 106 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : null; |
| 107 |
|
| 108 |
if ( ! wp_verify_nonce( $nonce, 'yaymail_nonce' ) ) { |
| 109 |
wp_send_json_error( array( 'status' => 'Wrong nonce validate!' ) ); |
| 110 |
exit(); |
| 111 |
} |
| 112 |
update_option( 'yaymail_notice', time() + 60 * 60 * 24 * 60 ); // After 60 days show |
| 113 |
wp_send_json_success(); |
| 114 |
} |
| 115 |
wp_send_json_error( array( 'message' => 'Update fail!' ) ); |
| 116 |
} |
| 117 |
|
| 118 |
public function plugin_action_links( $links ) { |
| 119 |
$action_links = array( |
| 120 |
'settings' => '<a href="' . admin_url( 'admin.php?page=yaymail-settings' ) . '" aria-label="' . esc_attr__( 'View WooCommerce Email Builder', 'yaymail' ) . '">' . esc_html__( 'Start Customizing', 'yaymail' ) . '</a>', |
| 121 |
); |
| 122 |
$links[] = '<a target="_blank" href="https://yaycommerce.com/yaymail-woocommerce-email-customizer/" style="color: #43B854; font-weight: bold">' . __( 'Go Pro', 'yaymail' ) . '</a>'; |
| 123 |
return array_merge( $action_links, $links ); |
| 124 |
} |
| 125 |
|
| 126 |
public function add_support_and_docs_links( $plugin_meta, $plugin_file ) { |
| 127 |
if ( YAYMAIL_PLUGIN_BASENAME === $plugin_file ) { |
| 128 |
$plugin_meta[] = '<a target="_blank" href="https://docs.yaycommerce.com/yaymail/getting-started/introduction">Docs</a>'; |
| 129 |
$plugin_meta[] = '<a target="_blank" href="https://yaycommerce.com/support/">Support</a>'; |
| 130 |
} |
| 131 |
return $plugin_meta; |
| 132 |
} |
| 133 |
|
| 134 |
public function registerCustomPostType() { |
| 135 |
$labels = array( |
| 136 |
'name' => __( 'Email Template', 'yaymail' ), |
| 137 |
'singular_name' => __( 'Email Template', 'yaymail' ), |
| 138 |
'add_new' => __( 'Add New Email Template', 'yaymail' ), |
| 139 |
'add_new_item' => __( 'Add a new Email Template', 'yaymail' ), |
| 140 |
'edit_item' => __( 'Edit Email Template', 'yaymail' ), |
| 141 |
'new_item' => __( 'New Email Template', 'yaymail' ), |
| 142 |
'view_item' => __( 'View Email Template', 'yaymail' ), |
| 143 |
'search_items' => __( 'Search Email Template', 'yaymail' ), |
| 144 |
'not_found' => __( 'No Email Template found', 'yaymail' ), |
| 145 |
'not_found_in_trash' => __( 'No Email Template currently trashed', 'yaymail' ), |
| 146 |
'parent_item_colon' => '', |
| 147 |
); |
| 148 |
$capabilities = array(); |
| 149 |
$args = array( |
| 150 |
'labels' => $labels, |
| 151 |
'public' => true, |
| 152 |
'publicly_queryable' => true, |
| 153 |
'show_ui' => false, |
| 154 |
'query_var' => true, |
| 155 |
'rewrite' => true, |
| 156 |
'capability_type' => 'yaymail_template', |
| 157 |
'capabilities' => $capabilities, |
| 158 |
'hierarchical' => false, |
| 159 |
'menu_position' => null, |
| 160 |
'exclude_from_search' => true, |
| 161 |
'publicly_queryable' => false, |
| 162 |
'supports' => array( 'title', 'author', 'thumbnail' ), |
| 163 |
); |
| 164 |
register_post_type( 'yaymail_template', $args ); |
| 165 |
} |
| 166 |
public function settingsMenu() { |
| 167 |
add_submenu_page( 'yaycommerce', __( 'Email Builder Settings', 'yaymail' ), __( 'YayMail', 'yaymail' ), 'manage_woocommerce', $this->getPageId(), array( $this, 'settingsPage' ), 0 ); |
| 168 |
} |
| 169 |
|
| 170 |
public function nitWebPluginRegisterButtons( $buttons ) { |
| 171 |
$buttons[] = 'table'; |
| 172 |
$buttons[] = 'searchreplace'; |
| 173 |
$buttons[] = 'visualblocks'; |
| 174 |
$buttons[] = 'code'; |
| 175 |
$buttons[] = 'insertdatetime'; |
| 176 |
$buttons[] = 'autolink'; |
| 177 |
$buttons[] = 'contextmenu'; |
| 178 |
$buttons[] = 'advlist'; |
| 179 |
return $buttons; |
| 180 |
} |
| 181 |
|
| 182 |
public function njtWebPluginRegisterPlugin( $plugin_array ) { |
| 183 |
$plugin_array['table'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/table/plugin.min.js'; |
| 184 |
$plugin_array['searchreplace'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/searchreplace/plugin.min.js'; |
| 185 |
$plugin_array['visualblocks'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/visualblocks/plugin.min.js'; |
| 186 |
$plugin_array['code'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/code/plugin.min.js'; |
| 187 |
$plugin_array['insertdatetime'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/insertdatetime/plugin.min.js'; |
| 188 |
$plugin_array['autolink'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/autolink/plugin.min.js'; |
| 189 |
$plugin_array['contextmenu'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/contextmenu/plugin.min.js'; |
| 190 |
$plugin_array['advlist'] = YAYMAIL_PLUGIN_URL . 'assets/tinymce/advlist/plugin.min.js'; |
| 191 |
return $plugin_array; |
| 192 |
} |
| 193 |
|
| 194 |
public function settingsPage() { |
| 195 |
// When load this page will not show adminbar |
| 196 |
?> |
| 197 |
<style type="text/css"> |
| 198 |
#wpcontent, #footer {opacity: 0} |
| 199 |
#adminmenuback, #adminmenuwrap { display: none !important; } |
| 200 |
</style> |
| 201 |
<script type="text/javascript" id="yaymail-onload"> |
| 202 |
jQuery(document).ready( function() { |
| 203 |
jQuery('#adminmenuback, #adminmenuwrap').remove(); |
| 204 |
}); |
| 205 |
</script> |
| 206 |
<?php |
| 207 |
// add new buttons |
| 208 |
add_filter( 'mce_buttons', array( $this, 'nitWebPluginRegisterButtons' ) ); |
| 209 |
|
| 210 |
// Load the TinyMCE plugin |
| 211 |
add_filter( 'mce_external_plugins', array( $this, 'njtWebPluginRegisterPlugin' ) ); |
| 212 |
$viewPath = YAYMAIL_PLUGIN_PATH . 'views/pages/html-settings.php'; |
| 213 |
include_once $viewPath; |
| 214 |
} |
| 215 |
|
| 216 |
public function enqueueAdminScripts( $screenId ) { |
| 217 |
if ( class_exists( 'SitePress' ) ) { |
| 218 |
global $sitepress_settings, $sitepress; |
| 219 |
$custom_posts_sync = $sitepress_settings['custom_posts_sync_option']; |
| 220 |
$custom_posts_sync['yaymail_template'] = 0; |
| 221 |
$sitepress->set_setting( 'custom_posts_sync_option', $custom_posts_sync, true ); |
| 222 |
} |
| 223 |
if ( class_exists( 'Polylang' ) ) { |
| 224 |
$polylang_options = get_option( 'polylang' ); |
| 225 |
if ( isset( $polylang_options['post_types'] ) ) { |
| 226 |
$yaymail_template_position = array_search( 'yaymail_template', $polylang_options['post_types'] ); |
| 227 |
if ( false !== $yaymail_template_position ) { |
| 228 |
$polylang_options['post_types'] = array_splice( $polylang_options['post_types'], $yaymail_template_position + 1, 1 ); |
| 229 |
update_option( 'polylang', $polylang_options ); |
| 230 |
} |
| 231 |
} |
| 232 |
} |
| 233 |
if ( strpos( $screenId, 'yaymail-settings' ) !== false && class_exists( 'WC_Emails' ) ) { |
| 234 |
// Filter to active tinymce |
| 235 |
add_filter( 'user_can_richedit', '__return_true', PHP_INT_MAX ); |
| 236 |
// Get list template from Woo |
| 237 |
$wc_emails = \WC_Emails::instance(); |
| 238 |
$this->emails = (array) $wc_emails::instance()->emails; |
| 239 |
unset( $this->emails['WC_TrackShip_Email_Manager'] ); |
| 240 |
if ( isset( $this->emails['WC_GZD_Email_Customer_Shipment'] ) ) { |
| 241 |
$partial_email = new stdClass(); |
| 242 |
$partial_email->id = 'customer_partial_shipment'; |
| 243 |
$partial_email->title = 'Order partial shipped'; |
| 244 |
$customer_shipment_position = array_search( 'WC_GZD_Email_Customer_Shipment', array_keys( $this->emails ) ); |
| 245 |
$this->emails = array_merge( |
| 246 |
array_slice( $this->emails, 0, $customer_shipment_position ), |
| 247 |
array( 'WC_GZD_Email_Customer_Partial_Shipment' => $partial_email ), |
| 248 |
array_slice( $this->emails, $customer_shipment_position ) |
| 249 |
); |
| 250 |
} |
| 251 |
if ( class_exists( 'AW_Referrals_Plugin_Data' ) && ( is_plugin_active( 'yaymail-addon-for-automatewoo/yaymail-automatewoo.php' ) || is_plugin_active( 'email-customizer-automatewoo/yaymail-automatewoo.php' ) ) ) { |
| 252 |
$referrals_email = new stdClass(); |
| 253 |
$referrals_email->id = 'AutomateWoo_Referrals_Email'; |
| 254 |
$referrals_email->title = __( 'AutomateWoo Referrals Email', 'yaymail' ); |
| 255 |
$this->emails = array_merge( $this->emails, array( 'AutomateWoo_Referrals_Email' => $referrals_email ) ); |
| 256 |
} |
| 257 |
// Insert database all order template from Woo |
| 258 |
$templateEmail = Templates::getInstance(); |
| 259 |
$templates = $templateEmail::getList(); |
| 260 |
|
| 261 |
foreach ( $templates as $key => $template ) { |
| 262 |
if ( ! CustomPostType::postIDByTemplate( $key ) ) { |
| 263 |
$arr = array( |
| 264 |
'mess' => '', |
| 265 |
'post_date' => current_time( 'Y-m-d H:i:s' ), |
| 266 |
'post_type' => 'yaymail_template', |
| 267 |
'post_status' => 'publish', |
| 268 |
'_yaymail_template' => $key, |
| 269 |
'_email_backgroundColor_settings' => 'rgb(236, 236, 236)', |
| 270 |
'_yaymail_elements' => json_decode( $template['elements'], true ), |
| 271 |
|
| 272 |
); |
| 273 |
$insert = CustomPostType::insert( $arr ); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
/* |
| 278 |
@@@@ Enable Disable |
| 279 |
@@@@ note: Note the default value section is required when displaying in vue |
| 280 |
*/ |
| 281 |
|
| 282 |
$settingDefaultEnableDisable = array( |
| 283 |
'new_order' => 1, |
| 284 |
'cancelled_order' => 1, |
| 285 |
'failed_order' => 1, |
| 286 |
'customer_on_hold_order' => 1, |
| 287 |
'customer_processing_order' => 1, |
| 288 |
'customer_completed_order' => 1, |
| 289 |
'customer_refunded_order' => 1, |
| 290 |
'customer_invoice' => 0, |
| 291 |
'customer_note' => 0, |
| 292 |
'customer_reset_password' => 0, |
| 293 |
'customer_new_account' => 0, |
| 294 |
); |
| 295 |
|
| 296 |
$settingEnableDisables = ( CustomPostType::templateEnableDisable( false ) ) ? CustomPostType::templateEnableDisable( false ) : $settingDefaultEnableDisable; |
| 297 |
|
| 298 |
foreach ( $this->emails as $key => $value ) { |
| 299 |
if ( 'ORDDD_Email_Delivery_Reminder' == $key ) { |
| 300 |
$value->id = 'orddd_delivery_reminder_customer'; |
| 301 |
} |
| 302 |
if ( 'WCVendors_Admin_Notify_Approved' == $key ) { |
| 303 |
$value->id = 'admin_notify_approved'; |
| 304 |
} |
| 305 |
if ( ! array_key_exists( $value->id, $settingEnableDisables ) ) { |
| 306 |
$settingEnableDisables[ $value->id ] = '0'; |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
$this->emails = apply_filters( 'YaymailCreateFollowUpTemplates', $this->emails ); |
| 311 |
$settingEnableDisables = apply_filters( 'YaymailCreateSelectFollowUpTemplates', $settingEnableDisables ); |
| 312 |
|
| 313 |
$this->emails = apply_filters( 'YaymailCreateAutomateWooTemplates', $this->emails ); |
| 314 |
$settingEnableDisables = apply_filters( 'YaymailCreateSelectAutomateWooTemplates', $settingEnableDisables ); |
| 315 |
|
| 316 |
$this->emails = apply_filters( 'YaymailCreateTrackShipWooTemplates', $this->emails ); |
| 317 |
$settingEnableDisables = apply_filters( 'YaymailCreateSelectTrackShipWooTemplates', $settingEnableDisables ); |
| 318 |
|
| 319 |
$this->emails = apply_filters( 'YaymailCreateWCFMWooFMTemplates', $this->emails ); |
| 320 |
$settingEnableDisables = apply_filters( 'YaymailCreateSelectWCFMWooFMTemplates', $settingEnableDisables ); |
| 321 |
|
| 322 |
$this->emails = apply_filters( 'YaymailCreateGermanMarketTemplates', $this->emails ); |
| 323 |
|
| 324 |
$this->emails = apply_filters( 'YaymailCreateListYWCESTemplates', $this->emails ); |
| 325 |
$settingEnableDisables = apply_filters( 'YaymailCreateSelectYWCESTemplates', $settingEnableDisables ); |
| 326 |
|
| 327 |
$this->emails = apply_filters( 'YaymailCreateWcCartAbandonmentRecoveryTemplates', $this->emails ); |
| 328 |
$settingEnableDisables = apply_filters( 'YaymailCreateSelectWcCartAbandonmentRecoveryTemplates', $settingEnableDisables ); |
| 329 |
|
| 330 |
$settingDefaultGenerals = array( |
| 331 |
'payment' => 2, |
| 332 |
'product_image' => 0, |
| 333 |
'image_size' => 'thumbnail', |
| 334 |
'image_width' => '30px', |
| 335 |
'image_height' => '30px', |
| 336 |
'product_sku' => 1, |
| 337 |
'product_des' => 0, |
| 338 |
'product_hyper_links' => 0, |
| 339 |
'product_regular_price' => 0, |
| 340 |
'product_item_cost' => 0, |
| 341 |
'background_color_table_items' => '#e5e5e5', |
| 342 |
'content_items_color' => '#636363', |
| 343 |
'title_items_color' => '#7f54b3', |
| 344 |
'container_width' => '605px', |
| 345 |
'order_url' => '', |
| 346 |
'custom_css' => '', |
| 347 |
'enable_css_custom' => 'no', |
| 348 |
'image_position' => 'Top', |
| 349 |
); |
| 350 |
$settingGenerals = get_option( 'yaymail_settings' ) ? get_option( 'yaymail_settings' ) : $settingDefaultGenerals; |
| 351 |
foreach ( $settingDefaultEnableDisable as $keyDefaultEnableDisable => $settingDefaultEnableDisable ) { |
| 352 |
if ( ! array_key_exists( $keyDefaultEnableDisable, $settingEnableDisables ) ) { |
| 353 |
$settingEnableDisables[ $keyDefaultEnableDisable ] = $settingDefaultEnableDisable; |
| 354 |
}; |
| 355 |
} |
| 356 |
$settings['enableDisable'] = $settingEnableDisables; |
| 357 |
|
| 358 |
/* |
| 359 |
@@@@ General |
| 360 |
@@@@ note: Note the default value section is required when displaying in vue |
| 361 |
*/ |
| 362 |
|
| 363 |
$settingGenerals = get_option( 'yaymail_settings' ) ? get_option( 'yaymail_settings' ) : $settingDefaultGenerals; |
| 364 |
foreach ( $settingDefaultGenerals as $keyDefaultGeneral => $settingGeneral ) { |
| 365 |
if ( ! array_key_exists( $keyDefaultGeneral, $settingGenerals ) ) { |
| 366 |
$settingGenerals[ $keyDefaultGeneral ] = $settingDefaultGenerals[ $keyDefaultGeneral ]; |
| 367 |
}; |
| 368 |
} |
| 369 |
|
| 370 |
$settingGenerals['direction_rtl'] = get_option( 'yaymail_direction' ) ? get_option( 'yaymail_direction' ) : 'ltr'; |
| 371 |
$settings['general'] = $settingGenerals; |
| 372 |
|
| 373 |
$scriptId = $this->getPageId(); |
| 374 |
$order = CustomPostType::getListOrders(); |
| 375 |
|
| 376 |
wp_deregister_script( 'vue' ); |
| 377 |
wp_deregister_script( 'vuex' ); |
| 378 |
|
| 379 |
wp_enqueue_script( 'vue', YAYMAIL_PLUGIN_URL . ( YAYMAIL_DEBUG ? 'assets/libs/vue.js' : 'assets/libs/vue.min.js' ), '', YAYMAIL_VERSION, true ); |
| 380 |
wp_enqueue_script( 'vuex', YAYMAIL_PLUGIN_URL . 'assets/libs/vuex.js', '', YAYMAIL_VERSION, true ); |
| 381 |
|
| 382 |
wp_enqueue_script( $scriptId, YAYMAIL_PLUGIN_URL . 'assets/dist/js/main.js', array( 'jquery' ), YAYMAIL_VERSION, true ); |
| 383 |
wp_enqueue_style( $scriptId, YAYMAIL_PLUGIN_URL . 'assets/dist/css/main.css', array(), YAYMAIL_VERSION ); |
| 384 |
|
| 385 |
wp_enqueue_script( $scriptId . '-script', YAYMAIL_PLUGIN_URL . 'assets/admin/js/script.js', '', YAYMAIL_VERSION, true ); |
| 386 |
wp_enqueue_script( $scriptId . '-plugin-install', YAYMAIL_PLUGIN_URL . 'assets/admin/js/plugin-install.js', '', YAYMAIL_VERSION, true ); |
| 387 |
$yaymailSettings = get_option( 'yaymail_settings' ); |
| 388 |
|
| 389 |
// Load ACE Editor -Start |
| 390 |
if ( isset( $yaymailSettings['enable_css_custom'] ) && 'yes' == $yaymailSettings['enable_css_custom'] ) { |
| 391 |
wp_enqueue_script( $scriptId . 'ace-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/ace.js', '', YAYMAIL_VERSION, true ); |
| 392 |
wp_enqueue_script( $scriptId . 'ace1-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/ext-language_tools.js', '', YAYMAIL_VERSION, true ); |
| 393 |
wp_enqueue_script( $scriptId . 'ace2-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/mode-css.js', '', YAYMAIL_VERSION, true ); |
| 394 |
wp_enqueue_script( $scriptId . 'ace3-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/theme-merbivore_soft.js', '', YAYMAIL_VERSION, true ); |
| 395 |
wp_enqueue_script( $scriptId . 'ace4-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/worker-css.js', '', YAYMAIL_VERSION, true ); |
| 396 |
wp_enqueue_script( $scriptId . 'ace5-script', YAYMAIL_PLUGIN_URL . 'assets/aceeditor/snippets/css.js ', '', YAYMAIL_VERSION, true ); |
| 397 |
} else { |
| 398 |
wp_dequeue_script( $scriptId . 'ace-script' ); |
| 399 |
wp_dequeue_script( $scriptId . 'ace1-script' ); |
| 400 |
wp_dequeue_script( $scriptId . 'ace2-script' ); |
| 401 |
wp_dequeue_script( $scriptId . 'ace3-script' ); |
| 402 |
wp_dequeue_script( $scriptId . 'ace4-script' ); |
| 403 |
wp_dequeue_script( $scriptId . 'ace5-script' ); |
| 404 |
} |
| 405 |
// Load ACE Editor -End |
| 406 |
// Css for page admin of WordPress. |
| 407 |
wp_enqueue_style( $scriptId . '-css', YAYMAIL_PLUGIN_URL . 'assets/admin/css/css.css', array(), YAYMAIL_VERSION ); |
| 408 |
$current_user = wp_get_current_user(); |
| 409 |
$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; |
| 410 |
$element = new DefaultElement(); |
| 411 |
$yaymailSettingsDefaultLogo = get_option( 'yaymail_settings_default_logo' ); |
| 412 |
$setDefaultLogo = false != $yaymailSettingsDefaultLogo ? $yaymailSettingsDefaultLogo['set_default'] : '0'; |
| 413 |
$yaymailSettingsDefaultFooter = get_option( 'yaymail_settings_default_footer' ); |
| 414 |
$setDefaultFooter = false != $yaymailSettingsDefaultFooter ? $yaymailSettingsDefaultFooter['set_default'] : '0'; |
| 415 |
if ( isset( $_GET['template'] ) || ! empty( $_GET['template'] ) ) { |
| 416 |
$req_template['id'] = sanitize_text_field( $_GET['template'] ); |
| 417 |
} else { |
| 418 |
$req_template['id'] = 'new_order'; |
| 419 |
} |
| 420 |
foreach ( $this->emails as $value ) { |
| 421 |
if ( is_array( $value ) ) { |
| 422 |
if ( $value['id'] == $req_template['id'] ) { |
| 423 |
$req_template['title'] = $value['title']; |
| 424 |
} |
| 425 |
} else { |
| 426 |
if ( $value->id == $req_template['id'] ) { |
| 427 |
$req_template['title'] = $value->title; |
| 428 |
} |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
$allowed_html_tags = wp_kses_allowed_html( 'post' ); |
| 433 |
$allowed_html_tags['style'] = array(); |
| 434 |
|
| 435 |
// List email supported |
| 436 |
$list_email_supported = PluginSupported::listAddonSupported(); |
| 437 |
$list_plugin_for_pro = PluginSupported::listPluginForProSupported(); |
| 438 |
|
| 439 |
$orderby = 'name'; |
| 440 |
$order_category = 'asc'; |
| 441 |
$hide_empty = false; |
| 442 |
|
| 443 |
$cat_args = array( |
| 444 |
'orderby' => $orderby, |
| 445 |
'order' => $order_category, |
| 446 |
'hide_empty' => $hide_empty, |
| 447 |
); |
| 448 |
|
| 449 |
$product_categories = get_terms( 'product_cat', $cat_args ); |
| 450 |
$les_promenades_fantomes = get_terms( 'les-promenades-fantomes', $cat_args ); |
| 451 |
$promas_service = get_terms( 'promas-service', $cat_args ); |
| 452 |
$billing_country = WC()->countries->countries; |
| 453 |
$arr_payment_methods = array(); |
| 454 |
$payment_methods = WC()->payment_gateways->payment_gateways; |
| 455 |
foreach ( $payment_methods as $key => $item ) { |
| 456 |
if ( 'yes' == $item->enabled ) { |
| 457 |
$arr_payment_methods[] = array( |
| 458 |
'id' => $item->id, |
| 459 |
'method_title' => ! empty( $item->method_title ) ? $item->method_title : $item->title, |
| 460 |
); |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
$get_shipping_methods = WC()->shipping->get_shipping_methods(); |
| 465 |
$data = array(); |
| 466 |
foreach ( $get_shipping_methods as $shipping_method ) { |
| 467 |
$item = array( |
| 468 |
'id' => $shipping_method->id, |
| 469 |
'method_title' => $shipping_method->method_title, |
| 470 |
); |
| 471 |
|
| 472 |
$data[] = $item; |
| 473 |
} |
| 474 |
|
| 475 |
$shipping_methods = $data; |
| 476 |
|
| 477 |
$data_coupon_codes = array(); |
| 478 |
$data_products = array(); |
| 479 |
$data_skus = array(); |
| 480 |
|
| 481 |
if ( is_plugin_active( 'yaymail-addon-conditional-logic/yaymail-conditional-logic.php' ) ) { |
| 482 |
global $wpdb; |
| 483 |
$get_coupon_codes = $wpdb->get_col( "SELECT post_name FROM $wpdb->posts WHERE post_type = 'shop_coupon' AND post_status = 'publish' ORDER BY post_name ASC LIMIT 20" ); |
| 484 |
foreach ( $get_coupon_codes as $coupon_codes ) { |
| 485 |
$item = |
| 486 |
str_replace( '-', ' ', $coupon_codes ); |
| 487 |
|
| 488 |
$data_coupon_codes[] = $item; |
| 489 |
} |
| 490 |
|
| 491 |
$get_products = $wpdb->get_results( "SELECT ID as id, post_title as name FROM $wpdb->posts WHERE post_type = 'product' AND post_status = 'publish' ORDER BY name ASC LIMIT 20" ); |
| 492 |
foreach ( $get_products as $product ) { |
| 493 |
$data_products[] = $product; |
| 494 |
} |
| 495 |
|
| 496 |
$get_product_skus = $wpdb->get_results( |
| 497 |
// "SELECT CONCAT(p.post_title, ' (#', pm.meta_value, ')') AS label, |
| 498 |
"SELECT |
| 499 |
DISTINCT(pm.meta_value) as sku, |
| 500 |
p.post_title AS name, |
| 501 |
p.ID AS id |
| 502 |
FROM {$wpdb->prefix}postmeta AS pm |
| 503 |
INNER JOIN {$wpdb->prefix}posts AS p |
| 504 |
ON pm.post_id = p.ID |
| 505 |
WHERE pm.meta_key = '_sku' |
| 506 |
AND p.post_type IN ('product', 'product_variation') |
| 507 |
AND p.post_status = 'publish' |
| 508 |
ORDER BY pm.meta_value ASC LIMIT 20" |
| 509 |
); |
| 510 |
foreach ( $get_product_skus as $skus ) { |
| 511 |
$data_skus[] = $skus; |
| 512 |
} |
| 513 |
} |
| 514 |
$coupon_codes = $data_coupon_codes; |
| 515 |
$products = $data_products; |
| 516 |
$product_skus = $data_skus; |
| 517 |
|
| 518 |
$arrayShortCode = array(); |
| 519 |
$yaymail_informations = Helper::inforShortcode( '', '', array() ); |
| 520 |
$shortcodeCustom = array_keys( apply_filters( 'yaymail_customs_shortcode', array(), $yaymail_informations, '' ) ); |
| 521 |
if ( ! empty( $shortcodeCustom ) ) { |
| 522 |
$arrItemShortcodeCus = array(); |
| 523 |
foreach ( $shortcodeCustom as $item ) { |
| 524 |
$name = __( 'Custom Shortcode For ', 'yaymail' ) . ucfirst( str_replace( array( '[', ']', 'yaymail_custom_shortcode_' ), '', $item ) ); |
| 525 |
array_push( $arrItemShortcodeCus, array( $item, $name ) ); |
| 526 |
} |
| 527 |
$arrayShortCode[] = array( |
| 528 |
'plugin' => __( 'Custom Shortcode', 'yaymail' ), |
| 529 |
'shortcode' => $arrItemShortcodeCus, |
| 530 |
); |
| 531 |
} |
| 532 |
|
| 533 |
$listShortCodeAddon = apply_filters( 'yaymail_list_shortcodes', $arrayShortCode ); |
| 534 |
// WooCommerce for LatePoint |
| 535 |
if ( class_exists( 'TechXelaLatePointPaymentsWooCommerce' ) ) { |
| 536 |
$listShortCodeAddon[] = array( |
| 537 |
'plugin' => 'WooCommerce for LatePoint', |
| 538 |
'shortcode' => array( |
| 539 |
array( '[yaymail_woo_latepoint_booking_detail]', 'WooCommerce Latepoint Booking Detail' ), |
| 540 |
|
| 541 |
array( '[yaymail_woo_latepoint_caption]', 'WooCommerce Latepoint caption' ), |
| 542 |
array( '[yaymail_woo_latepoint_bg_color]', 'WooCommerce Latepoint Bg Color' ), |
| 543 |
array( '[yaymail_woo_latepoint_text_color]', 'WooCommerce Latepoint Text Color' ), |
| 544 |
array( '[yaymail_woo_latepoint_font_size]', 'WooCommerce Latepoint Font Size' ), |
| 545 |
array( '[yaymail_woo_latepoint_border]', 'WooCommerce Latepoint Border' ), |
| 546 |
array( '[yaymail_woo_latepoint_border_radius]', 'WooCommerce Latepoint Border Radius' ), |
| 547 |
array( '[yaymail_woo_latepoint_margin]', 'WooCommerce Latepoint Margin' ), |
| 548 |
array( '[yaymail_woo_latepoint_padding]', 'WooCommerce Latepoint Padding' ), |
| 549 |
array( '[yaymail_woo_latepoint_css]', 'WooCommerce Latepoint css' ), |
| 550 |
array( '[yaymail_woo_latepoint_show_locations]', 'WooCommerce Latepoint Show Locations' ), |
| 551 |
array( '[yaymail_woo_latepoint_show_agents]', 'WooCommerce Latepoint Show Agents' ), |
| 552 |
array( '[yaymail_woo_latepoint_show_services]', 'WooCommerce Latepoint Show Services' ), |
| 553 |
array( '[yaymail_woo_latepoint_show_service_categories]', 'WooCommerce Latepoint Show Service Sategories' ), |
| 554 |
array( '[yaymail_woo_latepoint_selected_location]', 'WooCommerce Latepoint Selected Location' ), |
| 555 |
array( '[yaymail_woo_latepoint_selected_agent]', 'WooCommerce Latepoint Selected Agent' ), |
| 556 |
array( '[yaymail_woo_latepoint_selected_service]', 'WooCommerce Latepoint Selected Service' ), |
| 557 |
array( '[yaymail_woo_latepoint_selected_service_category]', 'WooCommerce Latepoint Selected Service Category' ), |
| 558 |
array( '[yaymail_woo_latepoint_selected_duration]', 'WooCommerce Latepoint Selected Duration' ), |
| 559 |
array( '[yaymail_woo_latepoint_selected_total_attendees]', 'WooCommerce Latepoint Selected Total Attendees' ), |
| 560 |
array( '[yaymail_woo_latepoint_hide_side_panel]', 'WooCommerce Latepoint Hide Side Panel' ), |
| 561 |
array( '[yaymail_woo_latepoint_hide_summary]', 'WooCommerce Latepoint Hide Summary' ), |
| 562 |
array( '[yaymail_woo_latepoint_calendar_start_date]', 'WooCommerce Latepoint Calendar Start Date' ), |
| 563 |
|
| 564 |
), |
| 565 |
); |
| 566 |
} |
| 567 |
|
| 568 |
$this->emails = array_map( |
| 569 |
function( $item ) { |
| 570 |
$final_item = new stdClass(); |
| 571 |
|
| 572 |
if ( is_array( $item ) ) { |
| 573 |
$final_item->id = $item['id']; |
| 574 |
$final_item->title = $item['title']; |
| 575 |
} else { |
| 576 |
$final_item->id = $item->id; |
| 577 |
$final_item->title = $item->title; |
| 578 |
} |
| 579 |
|
| 580 |
return $final_item; |
| 581 |
}, |
| 582 |
$this->emails |
| 583 |
); |
| 584 |
wp_localize_script( |
| 585 |
$scriptId, |
| 586 |
'yaymail_data', |
| 587 |
array( |
| 588 |
'orders' => $order, |
| 589 |
'imgUrl' => YAYMAIL_PLUGIN_URL . 'assets/dist/images', |
| 590 |
'nonce' => wp_create_nonce( 'email-nonce' ), |
| 591 |
'defaultDataElement' => $element->defaultDataElement, |
| 592 |
'home_url' => home_url(), |
| 593 |
'settings' => $settings, |
| 594 |
'admin_url' => get_admin_url(), |
| 595 |
'yaymail_plugin_url' => YAYMAIL_PLUGIN_URL, |
| 596 |
'wc_emails' => $this->emails, |
| 597 |
'default_email_test' => $default_email_test, |
| 598 |
'template' => $req_template, |
| 599 |
'set_default_logo' => $setDefaultLogo, |
| 600 |
'set_default_footer' => $setDefaultFooter, |
| 601 |
'list_plugin_for_pro' => $list_plugin_for_pro, |
| 602 |
'plugins' => apply_filters( 'yaymail_plugins', array() ), |
| 603 |
'list_email_supported' => $list_email_supported, |
| 604 |
'product_categories' => $product_categories, |
| 605 |
'les_promenades_fantomes' => $les_promenades_fantomes, |
| 606 |
'promas_service' => $promas_service, |
| 607 |
'billing_country' => $billing_country, |
| 608 |
'payment_methods' => $arr_payment_methods, |
| 609 |
'link_detail_smtp' => self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=yaysmtp§ion=description&TB_iframe=true&width=600&height=800' ), |
| 610 |
'yaymail_automatewoo_active' => ( is_plugin_active( 'yaymail-addon-for-automatewoo/yaymail-automatewoo.php' ) || is_plugin_active( 'email-customizer-automatewoo/yaymail-automatewoo.php' ) ) ? true : false, |
| 611 |
'yaymail_dokan_active' => is_plugin_active( 'yaymail-addon-for-dokan/yaymail-premium-addon-dokan.php' ) ? true : false, |
| 612 |
'yaysmtp_active' => $this->check_plugin_installed( 'yaysmtp/yay-smtp.php' ) || $this->check_plugin_installed( 'yaysmtp-pro/yay-smtp.php' ) ? true : false, |
| 613 |
'yaysmtp_setting' => admin_url( 'admin.php?page=yaysmtp' ), |
| 614 |
'list_shortcode_addon' => $listShortCodeAddon, |
| 615 |
'shipping_methods' => $shipping_methods, |
| 616 |
'coupon_codes' => $coupon_codes, |
| 617 |
'product_skus' => $product_skus, |
| 618 |
'i18n' => I18n::jsTranslate(), |
| 619 |
'products' => $products, |
| 620 |
'condition_values_page_size' => 20, |
| 621 |
) |
| 622 |
); |
| 623 |
do_action( 'yaymail_enqueue_script_conditional_logic' ); |
| 624 |
do_action( 'yaymail_before_enqueue_dependence' ); |
| 625 |
} |
| 626 |
wp_enqueue_script( 'yaymail-notice', YAYMAIL_PLUGIN_URL . 'assets/admin/js/notice.js', array( 'jquery' ), YAYMAIL_VERSION, false ); |
| 627 |
wp_localize_script( |
| 628 |
'yaymail-notice', |
| 629 |
'yaymail_notice', |
| 630 |
array( |
| 631 |
'admin_ajax' => admin_url( 'admin-ajax.php' ), |
| 632 |
'nonce' => wp_create_nonce( 'yaymail_nonce' ), |
| 633 |
) |
| 634 |
); |
| 635 |
} |
| 636 |
public function getPageId() { |
| 637 |
if ( null == $this->pageId ) { |
| 638 |
$this->pageId = YAYMAIL_PREFIX . '-settings'; |
| 639 |
} |
| 640 |
|
| 641 |
return $this->pageId; |
| 642 |
} |
| 643 |
public function check_plugin_installed( $plugin_slug ) { |
| 644 |
$installed_plugins = get_plugins(); |
| 645 |
return array_key_exists( $plugin_slug, $installed_plugins ) || in_array( $plugin_slug, $installed_plugins, true ); |
| 646 |
} |
| 647 |
|
| 648 |
public function search_by_meta_value_or_post_title( $q ) { |
| 649 |
if ( $title = $q->get( '_meta_or_title' ) ) { |
| 650 |
add_filter( |
| 651 |
'get_meta_sql', |
| 652 |
function( $sql ) use ( $title ) { |
| 653 |
global $wpdb; |
| 654 |
|
| 655 |
// Only run once: |
| 656 |
static $nr = 0; |
| 657 |
if ( 0 != $nr++ ) { |
| 658 |
return $sql; |
| 659 |
} |
| 660 |
// Modify WHERE part: |
| 661 |
$sql['where'] = sprintf( |
| 662 |
' AND ( %s OR %s ) ', |
| 663 |
$wpdb->prepare( "{$wpdb->posts}.post_title like '%%%s%%'", $title ), |
| 664 |
mb_substr( $sql['where'], 5, mb_strlen( $sql['where'] ) ) |
| 665 |
); |
| 666 |
return $sql; |
| 667 |
} |
| 668 |
); |
| 669 |
} |
| 670 |
} |
| 671 |
} |
| 672 |
|