PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.6.6
EmailKit – Email Customizer for WooCommerce & WP v1.6.6
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / Promotional / MetformPromoBanner / MetformPromoBanner.php

MetformPromoBanner.php in EmailKit – Email Customizer for WooCommerce & WP 1.6.6, at Promotional/MetformPromoBanner/MetformPromoBanner.php

351 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailKit\Promotional\MetformPromoBanner;
4
5 use Wpmet\UtilityPackage\Notice\Notice as LibsNotice;
6
7 defined('ABSPATH') || exit;
8
9 if (!class_exists('\EmailKit\Promotional\MetformPromoBanner\MetformPromoBanner')) {
10
11 class MetformPromoBanner
12 {
13
14 private $is_already_installed = '';
15
16 /**
17 * Constructor for initializing the class.
18 *
19 * @access public
20 * @return void
21 */
22 public function __construct()
23 {
24
25 do_action('metform_promo_banner_loaded');
26
27 if (empty($_GET['post_type']) || 'emailkit' !== $_GET['post_type']) {
28 return;
29 }
30
31 if (!function_exists('get_plugins')) {
32 include_once ABSPATH . 'wp-admin/includes/plugin.php';
33 }
34
35 $installed_plugins = get_plugins();
36 $this->is_already_installed = isset($installed_plugins['metform/metform.php']) ? 1 : 0;
37
38 $message = '
39
40 <div class="metform-promo-banner-wrapper">
41 <div class="metform-promo-banner-banner-left">
42 <div class="metform-promo-banner-banner-main">
43 <div class="metform-promo-banner-banner-logo">
44 <img src="' . plugin_dir_url(__FILE__) . '/assets/logo.svg" />
45 </div>
46 <div class="metform-promo-banner-banner-middle">
47 <div class="metform-promo-banner-banner-title">Boost Engagement with Custom Forms! 🚀</div>
48 <p>Struggling to grow your email list? Get <strong>FREE high-converting form templates</strong> designed to capture more leads, boost engagement, and turn visitors into loyal subscribers. 📩✨</p>
49 </div>
50 </div>
51 </div>
52 <div class="metform-promo-banner-banner-right">
53 <span class="metform-promo-banner-icon">
54 <abbr title="MetForm requires! Clicking the button will download MetForm and unlock all form templates.">
55 <div>
56 <span class="dashicons dashicons-info-outline"></span>
57 </div>
58 <div class="tooltip">
59 MetForm requires! Clicking the button will download MetForm and unlock all form templates.
60 </div>
61 </abbr>
62 </span>
63 <div class="metform-install-activate-btn">Try Free Templates</div>
64
65 </div>
66 </div>';
67
68 $dismissed_coutner = get_option('shopengine-metform_get_free_templates_banner_dismissed_' . get_current_user_id(), 0);
69 $notice_showing_delay_time = (3600 * 24 * 15);
70
71 if ($dismissed_coutner == 1) {
72 $notice_showing_delay_time = (3600 * 24 * 30);
73 } elseif ($dismissed_coutner == 2) {
74 $notice_showing_delay_time = (3600 * 24 * 180);
75 } elseif ($dismissed_coutner >= 3) {
76 $notice_showing_delay_time = (3600 * 24 * 99999);
77 }
78
79 LibsNotice::instance('shopengine', 'metform_get_free_templates_banner')
80 ->set_dismiss('user', $notice_showing_delay_time)
81 ->set_message($message)
82 ->call();
83
84 add_action('admin_head', [$this, 'metform_promotion_admin_head']);
85 }
86
87 public function metform_promotion_admin_head()
88 {
89 ?>
90 <style>
91 .notice-shopengine-metform_get_free_templates_banner {
92 background-image: url("<?php echo esc_url(plugin_dir_url(__FILE__) . '/assets/line_wp.svg') ?>") !important;
93 background-size: cover !important;
94 background-repeat: no-repeat !important;
95 background-position: center center !important;
96 border: none !important;
97 color: #ffffff;
98 font-family: "Roboto", sans-serif;
99 background-color: #1249D9;
100 }
101
102 .notice-shopengine-metform_get_free_templates_banner .metform-promo-banner-banner-main {
103 display: flex;
104 gap: 15px;
105 }
106
107 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width {
108 padding: 0;
109 margin: 0 !important;
110 box-shadow: 0px 1px 4px 0px #070B164D;
111 }
112
113 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width .metform-promo-banner-wrapper {
114 display: flex;
115 justify-content: space-between;
116 align-items: center;
117 }
118
119 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width .metform-promo-banner-wrapper .metform-promo-banner-banner-right {
120 display: flex;
121 align-items: center;
122 margin-right: 50px;
123 }
124
125 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width .metform-promo-banner-wrapper .metform-promo-banner-banner-right .metform-promo-banner-icon abbr {
126 text-decoration: none;
127 }
128
129 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width .metform-promo-banner-wrapper .metform-promo-banner-banner-right .metform-promo-banner-icon abbr span {
130 margin-right: 15px;
131 cursor: pointer;
132 color: #B0C5FA;
133 transition: all 0.3s ease-in-out;
134 }
135 .notice-shopengine-metform_get_free_templates_banner button.notice-dismiss {
136 padding: 0;
137 margin: 6px;
138 }
139
140 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width .metform-promo-banner-wrapper .metform-promo-banner-banner-right .metform-promo-banner-icon abbr span:hover {
141 color: #ffffff;
142 }
143
144 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width .metform-promo-banner-wrapper .metform-promo-banner-banner-left .metform-promo-banner-banner-main .metform-promo-banner-banner-logo {
145 padding: 24px 8px 0px 8px;
146 border-left: 6px solid #EEFF25;
147 background: #2A5BDD;
148 }
149
150 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width .metform-promo-banner-wrapper .metform-promo-banner-banner-left .metform-promo-banner-banner-middle {
151 padding: 20px 4px;
152 }
153
154 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width .metform-promo-banner-wrapper .metform-promo-banner-banner-left .metform-promo-banner-banner-middle p{
155 padding-bottom: 0;
156 margin-bottom: 0;
157 }
158
159 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width .metform-promo-banner-wrapper .metform-promo-banner-banner-right .metform-install-activate-btn {
160 font-size: 14px;
161 font-weight: 500;
162 padding: 12px 20px 10px;
163 background: #EEFF25;
164 color: #000000;
165 cursor: pointer;
166 border-radius: 4px;
167 transition: all 0.3s ease-in-out;
168 }
169 .notice-shopengine-metform_get_free_templates_banner .notice-container-full-width .metform-promo-banner-wrapper .metform-promo-banner-banner-right .metform-install-activate-btn:hover{
170 background-color: #ffffff;
171 color: #000;
172 }
173 .metform-promo-banner-banner-title {
174 font-size: 24px;
175 font-weight: 600;
176 margin-bottom: 8px;
177 margin-top: 6px;
178 letter-spacing: 0.1px;
179 }
180 .notice-shopengine-metform_get_free_templates_banner button.notice-dismiss:focus {
181 outline: none !important;
182 box-shadow: none !important;
183 }
184 .notice-shopengine-metform_get_free_templates_banner button.notice-dismiss::before {
185 content: "\f335";
186 color: #8BAAF6;
187 transition: all 0.3s ease-in-out;
188 font-size: 20px;
189 }
190 .notice-shopengine-metform_get_free_templates_banner button.notice-dismiss:hover::before {
191 color: #ffffff
192 }
193 .metform-promo-banner-icon {
194 position: relative;
195 display: inline-block;
196 }
197 .tooltip {
198 visibility: hidden;
199 position: absolute;
200 bottom: calc(100% + 15px);
201 right:15%;
202 background-color: #1a1f2d;
203 color: white;
204 padding: 12px 16px;
205 border-radius: 4px;
206 font-size: 14px;
207 font-weight: 400;
208 font-family: sans-serif;
209 width: 256px;;
210 box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
211 opacity: 0;
212 transition: opacity 0.2s, visibility 0.2s;
213 }
214
215 /* Triangle pointer */
216 .tooltip::after {
217 content: '';
218 position: absolute;
219 top: 100%;
220 right: 12px;
221 border-width: 8px;
222 border-style: solid;
223 border-color: #1a1f2d transparent transparent transparent;
224 }
225
226 .metform-promo-banner-icon:hover .tooltip {
227 visibility: visible;
228 opacity: 1;
229 }
230 </style>
231 <script type="text/javascript">
232 var metform_promo_banner_admin_var = {
233 adminurl: '<?php echo esc_url(admin_url()); ?>'
234 };
235
236 jQuery(document).ready(function($) {
237
238 const MetformInstallBtn = document.querySelector('.metform-install-activate-btn');
239
240 if (!MetformInstallBtn) {
241 return;
242 }
243
244 const isAlreadyInstalled = "<?php echo esc_attr($this->is_already_installed) ?>";
245 let installationUrl = "<?php echo esc_url($this->installation_url('metform/metform.php')) ?>";
246 let activationUrl = "<?php echo esc_url($this->activation_url('metform/metform.php')) ?>";
247 installationUrl = installationUrl?.replace(/&#038;/g, '&');
248 activationUrl = activationUrl?.replace(/&#038;/g, '&');
249
250 function metform_install_active_plugin(ajaxurl, success_callback, beforeText) {
251 try {
252 $.ajax({
253 type: "GET",
254 url: ajaxurl,
255 beforeSend: () => {
256 MetformInstallBtn.innerHTML = beforeText;
257 },
258 success: (response) => {
259 if (success_callback) {
260 success_callback();
261 } else {
262 window.location.href = window.metform_promo_banner_admin_var.adminurl + 'edit.php?post_type=metform-form&redirect_from=mf_promo_banner#show-metform-form-creation-modal';
263 }
264 },
265 error: function(error) {
266 console.error(error);
267 }
268 });
269 } catch (error) {
270 console.error("An error occurred:", error);
271 }
272 }
273
274 MetformInstallBtn.addEventListener('click', function(e) {
275
276 e.preventDefault();
277
278 if (isAlreadyInstalled === '0') {
279 metform_install_active_plugin.call(this, installationUrl, () => {
280 metform_install_active_plugin.call(this, activationUrl, null, 'Activating...');
281 }, 'Installing...');
282 } else if (isAlreadyInstalled === '1') {
283 metform_install_active_plugin.call(this, activationUrl, null, 'Activating...');
284 }
285 });
286 });
287 </script>
288 <?php
289 }
290
291 /**
292 * Get plugin installation url
293 *
294 * @access public
295 * @param string
296 * @return string
297 */
298 public function installation_url($pluginName)
299 {
300 $action = 'install-plugin';
301 $pluginSlug = $this->get_plugin_slug($pluginName);
302
303 return wp_nonce_url(
304 add_query_arg(
305 array(
306 'action' => $action,
307 'plugin' => $pluginSlug
308 ),
309 admin_url('update.php')
310 ),
311 $action . '_' . $pluginSlug
312 );
313 }
314
315 /**
316 * Get plugin slug
317 *
318 * @access public
319 * @param string
320 * @return string
321 */
322 public function get_plugin_slug($name)
323 {
324 $split = explode('/', $name);
325
326 return isset($split[0]) ? $split[0] : null;
327 }
328
329 /**
330 * Get plugin activation url
331 *
332 * @access public
333 * @param string
334 * @return string
335 */
336 public function activation_url($pluginName)
337 {
338
339 return wp_nonce_url(add_query_arg(
340 array(
341 'action' => 'activate',
342 'plugin' => $pluginName,
343 'plugin_status' => 'all',
344 'paged' => '1&s',
345 ),
346 admin_url('plugins.php')
347 ), 'activate-plugin_' . $pluginName);
348 }
349 }
350 }
351