PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.6.2
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.6.2
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / admin / class-notices.php

class-notices.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.6.2, at includes/admin/class-notices.php

109 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || die();
4
5 /**
6 * Components class.
7 *
8 * @since 1.1.0
9 * @SuppressWarnings(PHPMD.NPathComplexity)
10 */
11 class Sellkit_Notices {
12
13 /**
14 * Sellkit_Notices constructor.
15 *
16 * @since 1.1.0
17 */
18 public function __construct() {
19 $this->load_notices();
20
21 add_action( 'wp_ajax_sellkit_admin_notice_dismiss', [ $this, 'dismiss_notice' ] );
22 add_action( 'wp_ajax_sellkit_admin_notice_maybe_later', [ $this, 'handle_maybe_later_rating_btn' ] );
23 }
24
25 /**
26 * Handle maybe later button.
27 *
28 * @since 1.5.7
29 * @return void
30 */
31 public function handle_maybe_later_rating_btn() {
32 sellkit_update_option( 'sellkit_rating_notice_trigger', time() + 48 * 60 * 60 );
33 wp_send_json_success( esc_html__( 'The operation was successful.', 'sellkit' ) );
34 }
35
36 /**
37 * Load notices.
38 *
39 * @since 1.1.0
40 * @param string $plugin_name Plugin name.
41 */
42 public function load_notices( $plugin_name = 'sellkit' ) {
43 $path = trailingslashit( sellkit()->plugin_dir() . 'includes/admin/notices' );
44
45 if (
46 'sellkit-pro' === $plugin_name &&
47 sellkit()->has_pro &&
48 file_exists( sellkit_pro()->plugin_dir() . 'includes/admin/notices/notice-base.php' )
49 ) {
50 $path = trailingslashit( sellkit_pro()->plugin_dir() . 'includes/admin/notices' );
51 require_once sellkit_pro()->plugin_dir() . 'includes/admin/notices/notice-base.php';
52 }
53
54 $file_paths = glob( $path . '*.php' );
55
56 foreach ( $file_paths as $file_path ) {
57 if ( ! file_exists( $file_path ) ) {
58 continue;
59 }
60
61 require_once $file_path;
62
63 $file_name = str_replace( '.php', '', basename( $file_path ) );
64 $operator_class = str_replace( '-', ' ', $file_name );
65 $operator_class = str_replace( ' ', '_', ucwords( $operator_class ) );
66
67 if ( 'sellkit' === $plugin_name ) {
68 $operator_class = "Sellkit\Admin\Notices\\{$operator_class}";
69 }
70
71 if ( 'sellkit-pro' === $plugin_name && sellkit()->has_pro ) {
72 $operator_class = "Sellkit_Pro\Admin\Notices\\{$operator_class}";
73 }
74
75 if ( ! class_exists( $operator_class ) || 'notice-base' === $file_name ) {
76 continue;
77 }
78
79 $notice = new $operator_class();
80
81 if ( $notice->is_valid() ) {
82 add_action( 'admin_notices', [ $notice, 'notice_content_wrapper' ], $notice->priority() );
83 }
84 }
85
86 if ( sellkit()->has_pro && 'sellkit' === $plugin_name ) {
87 $this->load_notices( 'sellkit-pro' );
88 }
89 }
90
91 /**
92 * Dismiss notice handler.
93 *
94 * @since 1.1.0
95 */
96 public function dismiss_notice() {
97 check_ajax_referer( 'sellkit_admin', 'nonce' );
98
99 $new_notice_key = ! empty( $_POST['key'] ) ? sanitize_text_field( wp_unslash( $_POST['key'] ) ) : '';
100 $dismissed_notices = sellkit_get_option( 'dismissed_notices' );
101 $dismissed_notices = empty( $dismissed_notices ) ? [] : $dismissed_notices;
102 $new_dismissed_notices = array_merge( $dismissed_notices, [ $new_notice_key ] );
103
104 sellkit_update_option( 'dismissed_notices', array_filter( array_unique( $new_dismissed_notices ) ) );
105 }
106 }
107
108 new Sellkit_Notices();
109