PluginProbe
MailerLite – WooCommerce integration / 2.0
MailerLite – WooCommerce integration v2.0
3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 All 147 releases
woo-mailerlite / includes / functions.php

functions.php in MailerLite – WooCommerce integration 2.0, at includes/functions.php

151 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use MailerLite\Includes\Shared\Api\ApiType;
4
5 function woo_ml_valid_email($email)
6 {
7
8 if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
9
10 $email = explode("@", $email);
11
12 if (checkdnsrr(array_pop($email))) {
13
14 return true;
15 }
16 }
17
18 return false;
19 }
20
21 /**
22 * Check whether we are on our admin pages or not
23 *
24 * @return bool
25 */
26 function woo_ml_is_plugin_admin_area()
27 {
28 $screen = get_current_screen();
29
30 return (strpos($screen->id, 'wc-settings') !== false) ? true : false;
31 }
32
33 /**
34 * Debug
35 *
36 * @param $args
37 * @param bool $title
38 */
39 function woo_ml_debug($args, $title = false)
40 {
41
42 if ($title) {
43 echo '<h3>' . $title . '</h3>';
44 }
45
46 echo '<pre>';
47 print_r($args);
48 echo '</pre>';
49 }
50
51 /**
52 * Debug to log file
53 *
54 * @param $message
55 */
56 function woo_ml_debug_log($message)
57 {
58
59 if (WP_DEBUG === true && defined('WOO_ML_DEBUG') && WOO_ML_DEBUG === true) {
60 if (is_array($message) || is_object($message)) {
61 error_log(print_r($message, true));
62 } else {
63 error_log($message);
64 }
65 }
66 }
67
68 /**
69 * MailerLite universal script for tracking visits
70 * @return void
71 */
72 function mailerlite_universal_woo_commerce()
73 {
74
75 require_once WOO_MAILERLITE_DIR . 'includes/shared/api/class.woo-mailerlite-api-type.php';
76
77 if ((int)get_option('woo_mailerlite_platform', 1) === ApiType::CLASSIC) {
78
79 $shopUrl = home_url();
80 $shopUrl = str_replace('http://', '', $shopUrl);
81 $shopUrl = str_replace('https://', '', $shopUrl);
82
83 $popups_enabled = !get_option('mailerlite_popups_disabled');
84 $load = '';
85
86 if ($popups_enabled) {
87 $load = 'load';
88 }
89
90 ?>
91 <!-- MailerLite Universal -->
92 <script>
93 (function (m, a, i, l, e, r) {
94 m['MailerLiteObject'] = e;
95
96 function f() {
97 var c = {a: arguments, q: []};
98 var r = this.push(c);
99 return "number" != typeof r ? r : f.bind(c.q);
100 }
101
102 f.q = f.q || [];
103 m[e] = m[e] || f.bind(f.q);
104 m[e].q = m[e].q || f.q;
105 r = a.createElement(i);
106 var _ = a.getElementsByTagName(i)[0];
107 r.async = 1;
108 r.src = l + '?v' + (~~(new Date().getTime() / 1000000));
109 _.parentNode.insertBefore(r, _);
110 })(window, document, 'script', 'https://static.mailerlite.com/js/universal.js', 'ml');
111
112 window.mlsettings = window.mlsettings || {};
113 window.mlsettings.shop = '<?php echo $shopUrl; ?>';
114 var ml_account = ml('accounts', '<?php echo get_option("account_id"); ?>', '<?php echo get_option("account_subdomain"); ?>', '<?php echo $load; ?>');
115 ml('ecommerce', 'visitor', 'woocommerce');
116 </script>
117 <!-- End MailerLite Universal -->
118 <?php
119 }
120
121 if ((int)get_option('woo_mailerlite_platform', 1) === ApiType::CURRENT) {
122
123 $mailerlite_popups = !((get_option('mailerlite_popups_disabled') == '1'));
124 ?>
125 <!-- MailerLite Universal -->
126 <script>
127 (function (w, d, e, u, f, l, n) {
128 w[f] = w[f] || function () {
129 (w[f].q = w[f].q || [])
130 .push(arguments);
131 }, l = d.createElement(e), l.async = 1, l.src = u,
132 n = d.getElementsByTagName(e)[0], n.parentNode.insertBefore(l, n);
133 })
134 (window, document, 'script', 'https://assets.mailerlite.com/js/universal.js', 'ml');
135 ml('account', '<?php echo get_option('account_id'); ?>');
136 ml('enablePopups', <?php echo $mailerlite_popups ? 'true' : 'false'; ?>);
137 </script>
138 <!-- End MailerLite Universal -->
139 <?php
140 }
141 }
142
143 if (get_option('account_id') && get_option('account_subdomain')) {
144
145 add_action('wp_head', 'mailerlite_universal_woo_commerce');
146 }
147
148 if ((int)get_option('woo_mailerlite_platform', 1) === 2 && get_option('account_id')) {
149
150 add_action('wp_head', 'mailerlite_universal_woo_commerce');
151 }