PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 2.0.3
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v2.0.3
3.1.4 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 All 93 releases
ultimate-store-kit / dci / insights.php

insights.php in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 2.0.3, at dci/insights.php

772 lines 22.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Insights SDK File
5 * SDK Version 1.0.0
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 if ( ! class_exists( 'Insights_SDK' ) ) {
13
14 /**
15 * Insights SDK Class
16 */
17 class Insights_SDK {
18
19 public $version;
20
21 public $dci_name;
22 public $dci_allow_name;
23 public $dci_date_name;
24 public $dci_count_name;
25 public $nonce;
26 public $params;
27 public $text_domain;
28
29 /**
30 * Insights SDK Version
31 * param array $params
32 * @return void
33 */
34 public function __construct( $params ) {
35 $this->params = $params;
36 $this->text_domain = isset( $params['text_domain'] ) ? $params['text_domain'] : 'dci';
37 $this->version = isset( $params['sdk_version'] ) ? $params['sdk_version'] : '1.0.0';
38
39 add_action( 'wp_ajax_dci_sdk_insights', array( $this, 'dci_sdk_insights' ) );
40 add_action( 'wp_ajax_dci_sdk_dismiss_notice', array( $this, 'dci_sdk_dismiss_notice' ) );
41 add_action( 'wp_ajax_dci_sdk_insights_deactivate_feedback', array( $this, 'insights_deactivate_feedback' ) );
42
43 $security_key = md5( $params['plugin_name'] );
44 $this->dci_name = 'dci_' . str_replace( '-', '_', sanitize_title( $params['plugin_name'] ) . '_' . $security_key );
45 $this->dci_allow_name = 'dci_allow_status_' . $this->dci_name;
46 $this->dci_date_name = 'dci_status_date_' . $this->dci_name;
47 $dci_count_name = 'dci_attempt_count_' . $this->dci_name;
48 $dci_status_db = get_option( $this->dci_allow_name, false );
49
50 $this->nonce = wp_create_nonce( $this->dci_allow_name );
51
52 /**
53 * Deactivate Feedback
54 * Visible only in plugins.php
55 */
56 $this->deactivation_feedback( $params );
57
58 /**
59 * Modal Trigger if not init
60 * Show Notice Modal
61 */
62 if ( ! $dci_status_db ) {
63 $delay_check = $this->show_notice_delay_init( $params );
64 if ( $delay_check ) {
65 return;
66 }
67
68 $this->notice_modal( $params );
69 return;
70 }
71
72 /**
73 * If Disallow
74 */
75 if ( 'disallow' == $dci_status_db ) {
76 return;
77 }
78
79 /**
80 * Skip & Date Not Expired
81 * Show Notice Modal
82 */
83 if ( 'skip' == $dci_status_db && true == $this->check_date() ) {
84 $this->notice_modal( $params );
85 return;
86 }
87
88 /**
89 * Allowed & Date not Expired
90 * No need send data to server
91 * Else Send Data to Server
92 */
93 if ( ! $this->check_date() ) {
94 return;
95 }
96
97 /**
98 * Count attempt every time
99 */
100 $dci_attempt = get_option( $dci_count_name, 0 );
101
102 if ( ! $dci_attempt ) {
103 update_option( $dci_count_name, 1 );
104 }
105 update_option( $dci_count_name, $dci_attempt + 1 );
106
107 /**
108 * Next schedule date for attempt
109 */
110 update_option( $this->dci_date_name, gmdate( 'Y-m-d', strtotime( "+1 month" ) ) );
111
112 /**
113 * Prepare data
114 */
115 $this->data_prepare( $params );
116 }
117
118 /**
119 * Show Notice after time/days delay first time init
120 *
121 * Installed time less than means hide notice
122 */
123 public function show_notice_delay_init( $params ) {
124 if ( ! isset( $params['delay_time'] ) ) {
125 return false;
126 }
127 $installed = get_option( $this->dci_name . '_installed', false );
128
129 if ( ! $installed ) {
130 update_option( $this->dci_name . '_installed', time() );
131 }
132
133 $time = isset( $params['delay_time']['time'] ) ? $params['delay_time']['time'] : 60 * MINUTE_IN_SECONDS;
134
135 $installed = get_option( $this->dci_name . '_installed', false );
136
137 if ( $installed && ( time() - $installed ) < $time ) {
138 return true;
139 }
140
141 return false;
142 }
143
144 /**
145 * Insights Deactivate Feedback
146 */
147 public function insights_deactivate_feedback() {
148 $api_endpoint = isset( $_POST['api_endpoint'] ) ? sanitize_text_field( $_POST['api_endpoint'] ) : '';
149 $public_key = isset( $_POST['public_key'] ) ? sanitize_text_field( $_POST['public_key'] ) : '';
150 $product_id = isset( $_POST['product_id'] ) ? sanitize_text_field( $_POST['product_id'] ) : '';
151 $feedback = isset( $_POST['feedback'] ) ? sanitize_text_field( $_POST['feedback'] ) : '';
152 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : '';
153
154 if ( ! wp_verify_nonce( $nonce, 'dci_sdk' ) ) {
155 wp_send_json( array(
156 'status' => 'error',
157 'title' => 'Error',
158 'message' => 'Nonce verification failed',
159 ) );
160 wp_die();
161 }
162
163 if ( ! current_user_can( 'manage_options' ) ) {
164 wp_send_json( array(
165 'status' => 'error',
166 'title' => 'Error',
167 'message' => 'Denied, you don\'t have right permission',
168 ) );
169 wp_die();
170 }
171
172 $feedback = json_decode( stripslashes( $feedback ), true );
173
174 $data = array(
175 'api_endpoint' => $api_endpoint,
176 'public_key' => $public_key,
177 'product_id' => $product_id,
178 'feedback' => $feedback,
179 );
180
181 $this->data_prepare( $data );
182
183 wp_send_json( array(
184 'status' => 'success',
185 'title' => 'Success',
186 'message' => 'Success.',
187 ) );
188 wp_die();
189 }
190
191 /**
192 * Notice Modal
193 *
194 * @return void
195 */
196 public function notice_modal( $params ) {
197
198 $dci_data = array();
199 $dci_data['name'] = $this->dci_name;
200 $dci_data['date_name'] = $this->dci_date_name;
201 $dci_data['allow_name'] = $this->dci_allow_name;
202 $dci_data['nonce'] = wp_create_nonce( 'dci_sdk' );
203 $dci_data['slug'] = $params['slug'];
204 $dci_data['text_domain'] = $this->text_domain;
205
206 add_action( 'admin_enqueue_scripts', array( $this, 'dci_enqueue_scripts' ) );
207
208 /**
209 * If not current page
210 * Show Notice Modal & Return
211 */
212 if ( $params['current_page'] !== $params['menu_slug'] ) {
213 if ( ! get_transient( 'dismissed_notice_' . $this->dci_name ) ) {
214 add_action( 'admin_notices', array( $this, 'display_global_notice' ) );
215 }
216 return;
217 }
218
219 /**
220 * If Dismissed but always show welcome is true then show notice on welcome page
221 */
222 if ( ! isset( $params['always_show_welcome'] ) && get_transient( 'dismissed_notice_' . $this->dci_name ) ) {
223 return;
224 }
225
226 add_action( 'admin_notices', array( $this, 'display_global_notice' ) );
227
228 if ( isset( $params['popup_notice'] ) && true === $params['popup_notice'] ) {
229
230 include_once dirname( __FILE__ ) . '/notice.php';
231
232 add_action(
233 'in_admin_header',
234 function () use ($dci_data) {
235 if ( function_exists( 'dci_popup_notice' ) ) {
236 dci_popup_notice( $dci_data );
237 }
238 },
239 99999
240 );
241 }
242 }
243
244 /**
245 * Deactivate Feedback
246 *
247 * @return void
248 */
249 public function deactivation_feedback( $params ) {
250 $dci_data = array();
251 $dci_data['nonce'] = wp_create_nonce( 'dci_sdk' );
252 $dci_data['slug'] = $params['slug'];
253 $dci_data['text_domain'] = $this->text_domain;
254 $dci_data['api_endpoint'] = $params['api_endpoint'];
255 $dci_data['public_key'] = $params['public_key'];
256 $dci_data['product_id'] = $params['product_id'];
257 $dci_data['core_file'] = isset( $params['core_file'] ) ? $params['core_file'] : false;
258 $dci_data['plugin_deactivate_id'] = isset( $params['plugin_deactivate_id'] ) ? $params['plugin_deactivate_id'] : false;
259
260 add_action( 'admin_enqueue_scripts', array( $this, 'dci_enqueue_scripts' ) );
261
262 if ( isset( $params['deactivate_feedback'] ) && true === $params['deactivate_feedback'] ) {
263
264 include_once dirname( __FILE__ ) . '/deactivate-feedback.php';
265
266 $current_screen = get_admin_page_parent();
267
268 if ( isset( $current_screen ) && ! empty( $current_screen ) && 'plugins.php' === $current_screen ) {
269 add_action(
270 'in_admin_header',
271 function () use ($dci_data) {
272 if ( function_exists( 'dci_deactivate_feedback' ) ) {
273 dci_deactivate_feedback( $dci_data );
274 }
275 },
276 99999
277 );
278 }
279 }
280 }
281
282 /**
283 * If date is expired immidiate action
284 *
285 * @return boolean
286 */
287 public function check_date() {
288 $current_date = strtotime( gmdate( 'Y-m-d' ) );
289 $dci_status_date = strtotime( get_option( $this->dci_date_name, false ) );
290
291 if ( ! $dci_status_date ) {
292 return true;
293 }
294
295 if ( $dci_status_date && $current_date >= $dci_status_date ) {
296 return true;
297 }
298 return false;
299 }
300
301 /**
302 * Modal Trigger
303 *
304 * Not used
305 * @return boolean
306 */
307 public function modal_trigger() {
308
309 if ( ! wp_verify_nonce( $this->dci_allow_name, $this->nonce ) ) {
310 echo 'Nonce Verification Failed';
311 return false;
312 }
313
314 $sanitized_status = sanitize_text_field( $_GET['dci_allow_status'] );
315
316 if ( $sanitized_status == 'skip' ) {
317 update_option( $this->dci_allow_name, 'skip' );
318 /**
319 * Next schedule date for attempt
320 */
321 update_option( $this->dci_date_name, gmdate( 'Y-m-d', strtotime( "+1 month" ) ) );
322 return false;
323 } elseif ( $sanitized_status == 'yes' ) {
324 update_option( $this->dci_allow_name, 'yes' );
325 return true;
326 }
327
328 return false;
329 }
330
331 /**
332 * Reset Options Settings
333 * @return void
334 */
335 public function reset_settings() {
336 delete_option( $this->dci_allow_name );
337 delete_option( $this->dci_date_name );
338 }
339
340 /**
341 * Data prepare for send server
342 *
343 * @param array $server_url
344 * @return void
345 */
346 public function data_prepare( $params ) {
347 $server_url = isset( $params['api_endpoint'] ) ? $params['api_endpoint'] : false;
348 $public_key = isset( $params['public_key'] ) ? $params['public_key'] : false;
349 $custom_data = isset( $params['custom_data'] ) ? $params['custom_data'] : false;
350 $product_id = isset( $params['product_id'] ) ? $params['product_id'] : false;
351
352 if ( ! $server_url || ! $public_key ) {
353 return;
354 }
355
356 /**
357 * ==================================
358 *
359 * Start Own Custom Data Important
360 *
361 * ==================================
362 */
363 $custom_data = array(
364 'active_modules' => get_option( 'ultimate_store_kit_active_modules', false ),
365 'third_party' => get_option( 'ultimate_store_kit_edd_modules', false ),
366 'extend' => get_option( 'ultimate_store_kit_general_modules', false ),
367 );
368
369 $custom_data = wp_json_encode( $custom_data, true );
370
371 /**
372 * ==================================
373 *
374 * End Own Custom Important Data
375 *
376 * ==================================
377 */
378
379 $data = array();
380 $data['public_key'] = $public_key;
381 $data['product_id'] = $product_id;
382 $data['custom_data'] = $custom_data;
383
384 if ( isset( $params['feedback'] ) && ! empty( $params['feedback'] ) ) {
385 $data['feedback'] = $params['feedback'];
386 }
387
388 $non_sensitive_data = $this->dci_non_sensitve_data();
389 $data = array_merge( $data, $non_sensitive_data );
390
391 $this->dci_send_data_to_server( $server_url, $data );
392 }
393
394 /**
395 * Get the list of active and inactive plugins
396 *
397 * @return array
398 */
399 private function get_all_plugins() {
400 // Ensure get_plugins function is loaded
401 if ( ! function_exists( 'get_plugins' ) ) {
402 include ABSPATH . '/wp-admin/includes/plugin.php';
403 }
404
405 $plugins = get_plugins();
406 $active_plugins_keys = get_option( 'active_plugins', [] );
407 $active_plugins = [];
408
409 foreach ( $plugins as $k => $v ) {
410 // Take care of formatting the data how we want it.
411 $formatted = [];
412 $formatted['name'] = wp_strip_all_tags( $v['Name'] );
413
414 if ( isset( $v['Version'] ) ) {
415 $formatted['version'] = wp_strip_all_tags( $v['Version'] );
416 }
417
418 if ( isset( $v['Author'] ) ) {
419 $formatted['author'] = wp_strip_all_tags( $v['Author'] );
420 }
421
422 if ( isset( $v['Network'] ) ) {
423 $formatted['network'] = wp_strip_all_tags( $v['Network'] );
424 }
425
426 if ( isset( $v['PluginURI'] ) ) {
427 $formatted['plugin_uri'] = wp_strip_all_tags( $v['PluginURI'] );
428 }
429
430 if ( in_array( $k, $active_plugins_keys, true ) ) {
431 // Remove active plugins from list so we can show active and inactive separately
432 unset( $plugins[ $k ] );
433 $active_plugins[ $k ] = $formatted;
434 } else {
435 $plugins[ $k ] = $formatted;
436 }
437 }
438
439 $plugins_data = [];
440 foreach ( $active_plugins as $slug => $_plugin ) {
441 $slug = strstr( $slug, '/', true );
442
443 if ( ! $slug ) {
444 continue;
445 }
446
447 $plugins_data[ $slug ] = [
448 'name' => isset( $_plugin['name'] ) ? $_plugin['name'] : '',
449 'version' => isset( $_plugin['version'] ) ? $_plugin['version'] : '',
450 ];
451 }
452
453 return [
454 'active_plugins' => $active_plugins,
455 'inactive_plugins' => $plugins,
456 'plugins_data' => $plugins_data,
457 ];
458 }
459
460 /**
461 * Non sensitive data
462 *
463 * @return array
464 */
465 public function dci_non_sensitve_data() {
466 $current_user = wp_get_current_user();
467 $all_plugins = $this->get_all_plugins();
468
469 $users = get_users(
470 [
471 'role' => 'administrator',
472 'orderby' => 'ID',
473 'order' => 'ASC',
474 'number' => 1,
475 'paged' => 1,
476 ]
477 );
478
479 $admin_user = ( is_array( $users ) && ! empty( $users ) ) ? $users[0] : false;
480 $first_name = $current_user->first_name;
481 $last_name = $current_user->last_name;
482
483 if ( empty( $first_name ) && empty( $last_name ) ) {
484 $first_name = $current_user->display_name;
485 $last_name = null;
486 }
487
488 if ( $admin_user ) {
489 $first_name = $admin_user->first_name ? $admin_user->first_name : $admin_user->display_name;
490 $last_name = $admin_user->last_name;
491 }
492
493 $theme = wp_get_theme( get_stylesheet() );
494
495 $data = array(
496 'first_name' => $first_name,
497 'last_name' => $last_name,
498 'email' => get_option( 'admin_email' ),
499 'user_role' => $current_user->roles[0],
500 'website_url' => $current_user->user_url,
501 'website_data' => array(
502 'sdk_version' => $this->version,
503 'website_name' => get_bloginfo( 'name' ),
504 'wp_version' => get_bloginfo( 'version' ),
505 'php_version' => phpversion(),
506 'locale' => get_locale(),
507 'wp_multisite' => is_multisite() ? 'Yes' : 'No',
508 'wp_memory_limit' => defined( WP_MEMORY_LIMIT ) ? WP_MEMORY_LIMIT : false,
509 'memory_limit' => ini_get( 'memory_limit' ),
510
511 'inactive_plugins' => $all_plugins['inactive_plugins'],
512 'active_plugins' => $all_plugins['active_plugins'],
513 'active_plugins_count' => count( $all_plugins['active_plugins'] ),
514 'inactive_plugins_count' => count( $all_plugins['inactive_plugins'] ),
515
516 'theme_name' => $theme->get( 'Name' ),
517 'theme_version' => $theme->get( 'Version' ),
518 'theme_uri' => $theme->get( 'ThemeURI' ),
519 'theme_author' => $theme->get( 'Author' ),
520 ),
521 );
522
523 return $data;
524 }
525
526 /**
527 * Send data to server
528 *
529 * @param [string] $server_url
530 * @param [array] $data
531 * @return void
532 */
533 public function dci_send_data_to_server( $server_url, $data = null ) {
534
535 $args = array(
536 'method' => 'POST',
537 'timeout' => 60,
538 'headers' => array(
539 'Content-Type' => 'application/json',
540 'X-API-KEY' => $data['public_key'],
541 ),
542 'body' => wp_json_encode( $data ),
543 );
544
545 // error_log( print_r( $args, true ) );
546
547 $response = wp_remote_request( $server_url, $args );
548
549 if ( is_wp_error( $response ) ) {
550 // echo 'Error: ' . $response->get_error_message();
551 $this->reset_settings();
552 } else {
553 $response_data = wp_remote_retrieve_body( $response );
554 $response_data = json_decode( $response_data, true );
555 // print_r( $response_data );
556 if ( isset( $response_data['data']['status'] ) && 401 == $response_data['data']['status'] ) {
557 update_option( $this->dci_date_name, gmdate( 'Y-m-d', strtotime( "+3 days" ) ) );
558 }
559 }
560 }
561
562 /**
563 * Ajax callback
564 */
565 public function dci_sdk_insights() {
566 $sanitized_status = isset( $_POST['button_val'] ) ? sanitize_text_field( $_POST['button_val'] ) : '';
567 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : '';
568 $allow_name = isset( $_POST['allow_name'] ) ? sanitize_text_field( $_POST['allow_name'] ) : '';
569 $date_name = isset( $_POST['date_name'] ) ? sanitize_text_field( $_POST['date_name'] ) : '';
570
571 if ( ! wp_verify_nonce( $nonce, 'dci_sdk' ) ) {
572 wp_send_json( array(
573 'status' => 'error',
574 'title' => 'Error',
575 'message' => 'Nonce verification failed',
576 ) );
577 wp_die();
578 }
579
580 if ( ! current_user_can( 'manage_options' ) ) {
581 wp_send_json( array(
582 'status' => 'error',
583 'title' => 'Error',
584 'message' => 'Denied, you don\'t have right permission',
585 ) );
586 wp_die();
587 }
588
589 if ( 'disallow' == $sanitized_status ) {
590 update_option( $allow_name, 'disallow' );
591 }
592
593 if ( $sanitized_status == 'skip' ) {
594 update_option( $allow_name, 'skip' );
595 /**
596 * Next schedule date for attempt
597 */
598 update_option( $date_name, gmdate( 'Y-m-d', strtotime( "+1 month" ) ) );
599 } elseif ( $sanitized_status == 'yes' ) {
600 update_option( $allow_name, 'yes' );
601 }
602
603 wp_send_json( array(
604 'status' => 'success',
605 'title' => 'Success',
606 'message' => 'Success.',
607 ) );
608 wp_die();
609 }
610
611 /**
612 * Enqueue scripts and styles.
613 *
614 * @since 1.0.0
615 */
616 public function dci_enqueue_scripts() {
617 wp_enqueue_style( 'dci-sdk', plugins_url( 'assets/css/dci.css', __FILE__ ), array(), $this->version, 'all' );
618 wp_enqueue_script( 'dci-sdk', plugins_url( 'assets/js/dci.js', __FILE__ ), array( 'jquery' ), $this->version, true );
619 }
620
621 /**
622 * Display Global Notice
623 *
624 * @return void
625 */
626 public function display_global_notice() {
627 $menu_slug = isset( $this->params['menu_slug'] ) ? $this->params['menu_slug'] : 'javascript:void(0);';
628
629 $admin_url = add_query_arg( array(
630 'page' => $menu_slug,
631 ), admin_url( 'admin.php' ) );
632
633 $plugin_title = isset( $this->params['plugin_title'] ) ? $this->params['plugin_title'] : '';
634 $plugin_msg = isset( $this->params['plugin_msg'] ) ? $this->params['plugin_msg'] : '';
635 $plugin_icon = isset( $this->params['plugin_icon'] ) ? $this->params['plugin_icon'] : '';
636
637 ?>
638 <div
639 class="dci-global-notice dci-notice-data notice notice-success is-dismissible <?php echo esc_attr( substr( $this->dci_name, 0, -33 ) ); ?>">
640 <div class="dci-global-header bdt-dci-notice-global-header">
641 <?php if ( ! empty( $plugin_icon ) ) : ?>
642 <div class="bdt-dci-notice-logo">
643 <img src="<?php echo esc_url( $plugin_icon ); ?>" alt="icon">
644 </div>
645 <?php endif; ?>
646 <div class="bdt-dci-notice-content">
647 <h3>
648 <?php echo wp_kses_post( $plugin_title ); ?>
649 </h3>
650 <?php echo wp_kses_post( $plugin_msg ); ?>
651 <p>
652 <a href="<?php echo esc_url( $admin_url ); ?>">Learn More</a>?
653 </p>
654 <input type="hidden" name="dci_name" value="<?php echo esc_html( $this->dci_name ); ?>">
655 <input type="hidden" name="dci_date_name" value="<?php echo esc_html( $this->dci_date_name ); ?>">
656 <input type="hidden" name="dci_allow_name" value="<?php echo esc_html( $this->dci_allow_name ); ?>">
657 <input type="hidden" name="nonce" value="<?php echo esc_html( wp_create_nonce( 'dci_sdk' ) ); ?>">
658
659 <div class="bdt-dci-notice-button-wrap">
660 <button name="dci_allow_status" value="yes" class="dci-button-allow">
661 Yes, I'd Love To Contribute
662 </button>
663 <button name="dci_allow_status" value="skip" class="dci-button-skip">
664 Skip For Now
665 </button>
666 <button name="dci_allow_status" value="disallow" class="dci-button-disallow dci-button-danger">
667 No Thanks
668 </button>
669 </div>
670 </div>
671 </div>
672
673 </div>
674
675 <?php
676 }
677 public function __display_global_notice() {
678 $menu_slug = isset( $this->params['menu_slug'] ) ? $this->params['menu_slug'] : 'javascript:void(0);';
679
680 $admin_url = add_query_arg( array(
681 'page' => $menu_slug,
682 ), admin_url( 'admin.php' ) );
683
684 $plugin_title = isset( $this->params['plugin_title'] ) ? $this->params['plugin_title'] : '';
685 $plugin_msg = isset( $this->params['plugin_msg'] ) ? $this->params['plugin_msg'] : '';
686 $plugin_icon = isset( $this->params['plugin_icon'] ) ? $this->params['plugin_icon'] : '';
687
688 ?>
689 <div class="dci-global-notice dci-notice-data notice notice-success is-dismissible">
690 <div class="dci-global-header">
691 <?php if ( ! empty( $plugin_icon ) ) : ?>
692 <div>
693 <img src="<?php echo esc_url( $plugin_icon ); ?>" alt="icon">
694 </div>
695 <?php endif; ?>
696 <h3>
697 <?php printf( $plugin_title ); ?>
698 </h3>
699 </div>
700 <?php printf( $plugin_msg ); ?>
701 <p>
702 What we <a href="<?php echo esc_url( $admin_url ); ?>">collect</a>?
703 </p>
704 <input type="hidden" name="dci_name" value="<?php echo esc_html( $this->dci_name ); ?>">
705 <input type="hidden" name="dci_date_name" value="<?php echo esc_html( $this->dci_date_name ); ?>">
706 <input type="hidden" name="dci_allow_name" value="<?php echo esc_html( $this->dci_allow_name ); ?>">
707 <input type="hidden" name="nonce" value="<?php echo esc_html( wp_create_nonce( 'dci_sdk' ) ); ?>">
708 <p>
709 <button name="dci_allow_status" value="yes" class="button button-primary dci-button-allow">
710 Allow
711 </button>
712 <button name="dci_allow_status" value="skip" class="button dci-button-skip button-secondary">
713 I'll Skip For Now
714 </button>
715 <button name="dci_allow_status" value="disallow" class="button dci-button-disallow dci-button-danger">
716 Don't Allow
717 </button>
718 </p>
719 </div>
720 <?php
721 }
722
723 /**
724 * Dismiss Notice
725 *
726 * @return void
727 */
728 public function dci_sdk_dismiss_notice() {
729 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : '';
730 $dci_name = isset( $_POST['dci_name'] ) ? sanitize_text_field( $_POST['dci_name'] ) : '';
731
732 if ( ! wp_verify_nonce( $nonce, 'dci_sdk' ) ) {
733 wp_send_json( array(
734 'status' => 'error',
735 'title' => 'Error',
736 'message' => 'Nonce verification failed',
737 ) );
738 wp_die();
739 }
740
741 if ( ! current_user_can( 'manage_options' ) ) {
742 wp_send_json( array(
743 'status' => 'error',
744 'title' => 'Error',
745 'message' => 'Denied, you don\'t have right permission',
746 ) );
747 wp_die();
748 }
749
750 set_transient( 'dismissed_notice_' . $dci_name, true, 7 * DAY_IN_SECONDS );
751
752 wp_send_json( array(
753 'status' => 'success',
754 'title' => 'Success',
755 'message' => 'Success.',
756 ) );
757 wp_die();
758 }
759 }
760 }
761
762 /**
763 * Main Insights Function
764 */
765 if ( ! function_exists( 'dci_sdk_insights' ) ) {
766 function dci_sdk_insights( $params ) {
767 if ( class_exists( 'Insights_SDK' ) ) {
768 new Insights_SDK( $params );
769 }
770 }
771 }
772