PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.3.2
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.3.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.3.2, at includes/admin/class-notices.php

97 lines 2.5 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 }
23
24 /**
25 * Load notices.
26 *
27 * @since 1.1.0
28 * @param string $plugin_name Plugin name.
29 */
30 public function load_notices( $plugin_name = 'sellkit' ) {
31 $path = trailingslashit( sellkit()->plugin_dir() . 'includes/admin/notices' );
32
33 if (
34 'sellkit-pro' === $plugin_name &&
35 sellkit()->has_pro &&
36 file_exists( sellkit_pro()->plugin_dir() . 'includes/admin/notices/notice-base.php' )
37 ) {
38 $path = trailingslashit( sellkit_pro()->plugin_dir() . 'includes/admin/notices' );
39 require_once sellkit_pro()->plugin_dir() . 'includes/admin/notices/notice-base.php';
40 }
41
42 $file_paths = glob( $path . '*.php' );
43
44 foreach ( $file_paths as $file_path ) {
45 if ( ! file_exists( $file_path ) ) {
46 continue;
47 }
48
49 require_once $file_path;
50
51 $file_name = str_replace( '.php', '', basename( $file_path ) );
52 $operator_class = str_replace( '-', ' ', $file_name );
53 $operator_class = str_replace( ' ', '_', ucwords( $operator_class ) );
54
55 if ( 'sellkit' === $plugin_name ) {
56 $operator_class = "Sellkit\Admin\Notices\\{$operator_class}";
57 }
58
59 if ( 'sellkit-pro' === $plugin_name && sellkit()->has_pro ) {
60 $operator_class = "Sellkit_Pro\Admin\Notices\\{$operator_class}";
61 }
62
63 if ( ! class_exists( $operator_class ) || 'notice-base' === $file_name ) {
64 continue;
65 }
66
67 $notice = new $operator_class();
68
69 if ( $notice->is_valid() ) {
70 add_action( 'admin_notices', [ $notice, 'notice_content_wrapper' ], $notice->priority() );
71 }
72 }
73
74 if ( sellkit()->has_pro && 'sellkit' === $plugin_name ) {
75 $this->load_notices( 'sellkit-pro' );
76 }
77 }
78
79 /**
80 * Dismiss notice handler.
81 *
82 * @since 1.1.0
83 */
84 public function dismiss_notice() {
85 check_ajax_referer( 'sellkit_admin', 'nonce' );
86
87 $new_notice_key = ! empty( $_POST['key'] ) ? sanitize_text_field( wp_unslash( $_POST['key'] ) ) : '';
88 $dismissed_notices = sellkit_get_option( 'dismissed_notices' );
89 $dismissed_notices = empty( $dismissed_notices ) ? [] : $dismissed_notices;
90 $new_dismissed_notices = array_merge( $dismissed_notices, [ $new_notice_key ] );
91
92 sellkit_update_option( 'dismissed_notices', array_filter( array_unique( $new_dismissed_notices ) ) );
93 }
94 }
95
96 new Sellkit_Notices();
97