PluginProbe
WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation / trunk
WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation vtrunk
1.4.48 1.4.47 1.4.46 1.4.45 1.4.44 1.4.43 1.4.42 1.4.41 1.4.40 1.4.39 1.4.38 1.4.37 1.4.36 1.1.2 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 All 64 releases
optin / admin / class-admin.php

class-admin.php in WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation trunk, at admin/class-admin.php

471 lines 12.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore
2
3 namespace OPTN\Admin;
4
5 use OPTN\Includes\AbTesting;
6 use OPTN\Includes\Compatibility\CachingPlugins;
7 use OPTN\Includes\Db;
8 use OPTN\Includes\Integrations\Other\GoogleAnalytics;
9 use OPTN\Includes\Integrations\Other\Zapier;
10 use OPTN\Includes\Settings;
11 use OPTN\Includes\Notice\Notice;
12 use OPTN\Includes\Utils\Deactive;
13 use OPTN\Includes\Utils\PluginActions;
14 use OPTN\Includes\Utils\Utils;
15 use OPTN\Includes\WpxpoPlugins;
16 use OPTN\Includes\Xpo;
17
18 /**
19 * The admin-specific functionality of the plugin.
20 *
21 * @link https://wpxpo.com
22 * @since 1.0.0
23 *
24 * @package optin
25 * @subpackage optin/admin
26 */
27
28 /**
29 * The admin-specific functionality of the plugin.
30 *
31 * Defines the plugin name, version, and two examples hooks for how to
32 * enqueue the admin-specific stylesheet and JavaScript.
33 *
34 * @package optin
35 * @subpackage optin/admin
36 */
37 class Admin {
38
39 /**
40 * The ID of this plugin.
41 *
42 * @since 1.0.0
43 * @access private
44 * @var string $plugin_name The ID of this plugin.
45 */
46 private $plugin_name;
47
48 /**
49 * The version of this plugin.
50 *
51 * @since 1.0.0
52 * @access private
53 * @var string $version The current version of this plugin.
54 */
55 private $version;
56
57
58 /**
59 * Initialize the class and set its properties.
60 *
61 * @param string $plugin_name The name of this plugin.
62 * @param string $version The version of this plugin.
63 *
64 * @since 1.0.0
65 */
66 public function __construct( $plugin_name, $version ) {
67 $this->plugin_name = $plugin_name;
68 $this->version = $version;
69 Settings::init_settings( '1.0.0' );
70 $this->init_integrations();
71 $this->init_custom_hooks();
72 $this->init_scheduled_tasks();
73 new AbTesting();
74 new Deactive();
75 new Notice();
76 new WpxpoPlugins();
77 new PluginActions();
78 CachingPlugins::init();
79 add_action( 'in_admin_header', array( $this, 'remove_all_notices' ) );
80 }
81
82 /**
83 * Remove All Notification From Menu Page
84 *
85 * @return void
86 */
87 public function remove_all_notices() {
88 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash($_GET['page']) ) : ''; // phpcs:ignore
89 if ( strpos( $page, 'wowoptin' ) !== false ) {
90 remove_all_actions( 'admin_notices' );
91 remove_all_actions( 'all_admin_notices' );
92 remove_all_actions( 'in_admin_header' );
93 }
94 }
95
96 /**
97 * Initilizes custom hooks.
98 *
99 * @return void
100 */
101 public function init_custom_hooks() {
102 add_action(
103 'admin_footer',
104 function () {
105 $data = apply_filters( 'optn_activate_recipes', array() );
106 if ( is_array( $data ) && count( $data ) > 0 ) {
107 foreach ( $data as $d ) {
108 Db::get_instance()->activate_recipe( $d['id'], $d['args'] );
109 }
110 }
111 }
112 );
113 }
114
115 /**
116 * Init scheduled tasks
117 *
118 * @return void
119 */
120 public function init_scheduled_tasks() {
121 if ( ! wp_next_scheduled( 'optn_clean_db' ) ) {
122 wp_schedule_event( time(), 'weekly', 'optn_clean_db' );
123 }
124
125 add_action(
126 'optn_clean_db',
127 function () {
128 Db::get_instance()->clear_interactions( 30 );
129 }
130 );
131 }
132
133 /**
134 * Admin scripts and styles
135 *
136 * @return void
137 */
138 public function admin_head() {
139 if ( ! $this->is_in_menu_page() ) {
140 return;
141 }
142
143 if ( defined( 'OPTN_DEV_MODE' ) && true === OPTN_DEV_MODE ) {
144 echo '<script src="https://unpkg.com/react-scan/dist/auto.global.js"></script>'; // phpcs:ignore
145
146 echo '<link href="https://cdn.jsdelivr.net/npm/dom-to-image-more@3.5.0/spec/resources/fonts/web-fonts/embedded.min.css" rel="stylesheet" crossorigin="anonymous"><script src="https://cdn.jsdelivr.net/npm/dom-to-image-more@3.5.0/dist/dom-to-image-more.min.js"></script>'; // phpcs:ignore
147 }
148 }
149
150
151 /**
152 * Initilizes active integrations.
153 *
154 * @return void
155 */
156 private function init_integrations() {
157 $ints = Settings::get_integration_settings();
158
159 if ( isset( $ints['int_bg_enable_ga'] ) && true === $ints['int_bg_enable_ga'] ) {
160 new GoogleAnalytics();
161 }
162
163 if ( isset( $ints['int_bg_enable_zapier'] ) && true === $ints['int_bg_enable_zapier'] ) {
164 new Zapier();
165 }
166 }
167
168 /**
169 * Register all routes for admin
170 *
171 * @return void
172 */
173 public function register_routes() {
174 new RestAdmin();
175 }
176
177 /**
178 * Add admin menu pages
179 *
180 * @return void
181 */
182 public function add_menu_page() {
183
184 // Main Menu.
185 add_menu_page(
186 __( 'WowOptin', 'optin' ),
187 __( 'WowOptin', 'optin' ),
188 OPTN_MIN_CAPABILITY,
189 'wowoptin',
190 '',
191 OPTN_URL . '/assets/images/logo.svg',
192 26
193 );
194
195 $submenus = array(
196 array(
197 'title' => __( 'WowOptin Dashboard', 'optin' ),
198 'menu' => __( 'Dashboard', 'optin' ),
199 'slug' => 'wowoptin-dashboard',
200 ),
201 array(
202 'title' => __( 'WowOptin Optins', 'optin' ),
203 'menu' => __( 'Optins', 'optin' ),
204 'slug' => 'wowoptin-optins',
205 ),
206 array(
207 'title' => __( 'WowOptin Templates', 'optin' ),
208 'menu' => __( 'Templates', 'optin' ),
209 'slug' => 'wowoptin-templates',
210 ),
211 array(
212 'title' => __( 'WowOptin Leads', 'optin' ),
213 'menu' => __( 'Leads', 'optin' ),
214 'slug' => 'wowoptin-leads',
215 ),
216 array(
217 'title' => __( 'WowOptin A/B Testing', 'optin' ),
218 'menu' => __( 'A/B Testing', 'optin' ),
219 'slug' => 'wowoptin-ab-test',
220 ),
221 array(
222 'title' => __( 'WowOptin Integrations', 'optin' ),
223 'menu' => __( 'Integrations', 'optin' ),
224 'slug' => 'wowoptin-integrations',
225 ),
226 array(
227 'title' => __( 'WowOptin Settings', 'optin' ),
228 'menu' => __( 'Settings', 'optin' ),
229 'slug' => 'wowoptin-settings',
230 ),
231 array(
232 'title' => __( 'WowOptin License', 'optin' ),
233 'menu' => __( 'License', 'optin' ),
234 'slug' => Utils::is_show_license_page() ? 'wowoptin-license' : null,
235 ),
236 array(
237 'title' => __( 'Our Products', 'optin' ),
238 'menu' => __( 'Our Products', 'optin' ),
239 'slug' => 'wowoptin-wpxpo-plugins',
240 ),
241 array(
242 'title' => __( 'WowOptin Builder', 'optin' ),
243 'menu' => __( 'Builder', 'optin' ),
244 'slug' => 'wowoptin-builder', // DO NOT CHANGE.
245 ),
246 );
247
248 $pro_link = '';
249 $pro_link_text = '';
250
251 if ( ! Xpo::is_lc_active() ) {
252 $pro_link = 'https://www.wowoptin.com/#pricing';
253 $pro_link_text = __( 'Upgrade to Pro', 'optin' );
254 } elseif ( Xpo::is_lc_expired() ) {
255 $license_key = Utils::get_license_key() ?? '';
256 $pro_link = 'https://account.wpxpo.com/checkout/?edd_license_key=' . $license_key;
257 $pro_link_text = __( 'Renew License', 'optin' );
258 }
259
260 if ( ! empty( $pro_link ) ) {
261 ob_start();
262 ?>
263 <a href="<?php echo esc_url( $pro_link ); ?>" target="_blank" class="optn-pro-link">
264 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
265 <path d="M2.86 6.553a.5.5 0 01.823-.482l3.02 2.745c.196.178.506.13.64-.098L9.64 4.779a.417.417 0 01.72 0l2.297 3.939a.417.417 0 00.64.098l3.02-2.745a.5.5 0 01.823.482l-1.99 8.63a.833.833 0 01-.813.646H5.663a.833.833 0 01-.812-.646L2.86 6.553z" stroke="currentColor" stroke-width="1.5"></path>
266 </svg>
267 <span><?php echo esc_html( $pro_link_text ); ?></span>
268 </a>
269 <?php
270 $submenu_content = ob_get_clean();
271
272 $submenus[] = array(
273 'title' => __( 'WowOptin Pro', 'optin' ),
274 'menu' => $submenu_content,
275 'slug' => 'wowoptin-pro',
276 );
277 }
278
279 foreach ( $submenus as $i => $submenu ) {
280 if ( ! empty( $submenu['slug'] ) ) {
281 add_submenu_page(
282 'wowoptin',
283 $submenu['title'],
284 $submenu['menu'],
285 OPTN_MIN_CAPABILITY,
286 $submenu['slug'],
287 function () {},
288 $i
289 );
290 }
291 }
292
293 remove_submenu_page( 'wowoptin', 'wowoptin' );
294 }
295
296
297 /**
298 * Add dropdown html
299 *
300 * @return void
301 */
302 public function add_dropdown_html() {
303 ?>
304 <div id='optn-dropdown' style='display:none;' className='optn-portal'></div>
305 <?php
306
307 if ( isset( $_GET['page'] ) && 'wowoptin-builder' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
308 ?>
309 <div id="optn-builder-placeholder"></div>
310 <?php
311 }
312 }
313
314
315 /**
316 * Check if in plugin's menu page
317 *
318 * @return boolean
319 */
320 public function is_in_menu_page() {
321 return isset( $_GET['page'] ) && strpos( wp_unslash( $_GET['page'] ), 'wowoptin' ) !== false; // phpcs:ignore
322 }
323
324 /**
325 * Enqueue styles
326 *
327 * @return void
328 */
329 public function enqueue_styles() {
330
331 $inline_css = '
332 #toplevel_page_wowoptin li:has(a[href="admin.php?page=wowoptin-builder"]),
333 #toplevel_page_wowoptin li:has(a[href="admin.php?page=wowoptin-wpxpo-plugins"]) {
334 display:none;
335 }
336 #toplevel_page_wowoptin .wp-menu-image img {
337 width:20px;
338 height:20px;
339 padding: 7px 0 0;
340 }
341 #toplevel_page_wowoptin .wp-submenu a:hover {
342 color: #f97415 !important;
343 }
344 #toplevel_page_wowoptin .wp-submenu a[href*="wowoptin-pro"] {
345 display:none;
346 }
347 #toplevel_page_wowoptin .wp-submenu a.optn-pro-link {
348 display: flex;
349 align-items: center;
350 gap: 5px;
351 color: white !important;
352 background-color: #f97415 !important;
353 margin-inline: 10px;
354 border-radius: 6px;
355 margin-top: 6px;
356 padding-block: 6px;
357 box-shadow: none;
358 white-space: nowrap;
359 transition: background-color 200ms ease;
360 }
361 #toplevel_page_wowoptin .wp-submenu li.current a {
362 color: #f97415 !important;
363 }
364 #toplevel_page_wowoptin .wp-submenu a.optn-pro-link:hover {
365 background-color: #ea5a0c !important;
366 color: white !important;
367 }
368 ';
369
370 wp_add_inline_style( 'wp-admin', $inline_css );
371
372 if ( ! $this->is_in_menu_page() ) {
373 return;
374 }
375
376 wp_enqueue_style( $this->plugin_name . '-admin-css', OPTN_URL . 'admin/css/wowoptin-admin.min.css', array(), $this->version, 'all' );
377
378 $css_path = OPTN_URL . sprintf( '/build/admin/style-index%s.css', is_rtl() ? '-rtl' : '' );
379
380 wp_enqueue_style( $this->plugin_name . '-admin-build-css', $css_path, array(), $this->version, 'all' );
381 }
382
383 /**
384 * Enqueue scripts
385 *
386 * @return void
387 */
388 public function enqueue_scripts() {
389
390 if ( ! $this->is_in_menu_page() ) {
391 return;
392 }
393
394 // Compatibility for version <6.6.
395 global $wp_version;
396
397 if ( version_compare( $wp_version, '6.6', '<' ) ) {
398 wp_register_script(
399 'react-jsx-runtime',
400 OPTN_URL . 'assets/js/react-jsx-runtime.js',
401 array( 'react' ),
402 '18.3.0',
403 true
404 );
405 }
406
407 $assets = require_once OPTN_DIR . '/build/admin/index.asset.php';
408
409 // For media upload feature.
410 wp_enqueue_media();
411
412 wp_enqueue_script(
413 $this->plugin_name . '-admin-js',
414 OPTN_URL . 'build/admin/index.js',
415 $assets['dependencies'],
416 $assets['version'],
417 true
418 );
419
420 $currency_symbol = Utils::get_currency_symbol();
421
422 $lic_info = Utils::get_license_info();
423
424 $user = get_userdata( get_current_user_id() );
425
426 wp_localize_script(
427 $this->plugin_name . '-admin-js',
428 'optnAdmin',
429 array_merge(
430 array(
431 'links' => array(
432 'adminUrl' => admin_url( 'post-new.php' ),
433 'templateUrl' => admin_url( 'admin.php?page=wowoptin-templates' ),
434 'builderUrl' => admin_url( 'admin.php?page=wowoptin-builder' ),
435 'dashboardUrl' => admin_url( 'admin.php?page=wowoptin-dashboard' ),
436 'integrationUrl' => admin_url( 'admin.php?page=wowoptin-integrations' ),
437 'supportUrl' => admin_url( 'admin.php?page=wowoptin-support' ),
438 'optinsUrl' => admin_url( 'admin.php?page=wowoptin-optins' ),
439 'homeUrl' => get_home_url(),
440 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
441 'assetUrl' => OPTN_URL . 'assets',
442 ),
443
444 'userInfo' => array(
445 'name' => $user->user_firstname ? $user->user_firstname . ( $user->user_lastname ? ' ' . $user->user_lastname : '' ) : $user->display_name,
446 'email' => $user->user_email,
447 ),
448
449 'nonce' => wp_create_nonce( 'optin-nonce' ),
450 'restNonce' => wp_create_nonce( 'wp_rest' ),
451 'asset_dir' => OPTN_DIR . 'assets',
452 'server_time' => date_default_timezone_get(),
453 'currencySymbol' => $currency_symbol,
454 'curr_user' => wp_get_current_user()->display_name,
455 'dev_mode' => defined( 'OPTN_DEV_MODE' ) && OPTN_DEV_MODE ? 'true' : 'false',
456 'pro' => $lic_info['is_active'] ? 'true' : 'false',
457 'isExpired' => Xpo::is_lc_expired() ? 'true' : 'false',
458 'renewLink' => Xpo::get_renew_link(),
459 'settings' => Settings::get_settings(),
460 'audio' => Utils::get_audio_urls(),
461 'show_lic_page' => Utils::is_show_license_page() ? 'true' : 'false',
462 'version' => OPTN_VERSION,
463 'license' => Utils::get_license_key(),
464 'helloBar' => Notice::get_hellobar_config(),
465 ),
466 Xpo::get_wow_products_details()
467 )
468 );
469 }
470 }
471