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

74 lines 1.8 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 */
10 class Sellkit_Notices {
11
12 /**
13 * Sellkit_Notices constructor.
14 *
15 * @since 1.1.0
16 */
17 public function __construct() {
18 $this->load_notices();
19
20 add_action( 'wp_ajax_sellkit_admin_notice_dismiss', [ $this, 'dismiss_notice' ] );
21 }
22
23 /**
24 * Load notices.
25 *
26 * @since 1.1.0
27 */
28 public function load_notices() {
29 $path = trailingslashit( sellkit()->plugin_dir() . 'includes/admin/notices' );
30 $file_paths = glob( $path . '*.php' );
31
32 foreach ( $file_paths as $file_path ) {
33 if ( ! file_exists( $file_path ) ) {
34 continue;
35 }
36
37 require_once $file_path;
38
39 $file_name = str_replace( '.php', '', basename( $file_path ) );
40 $operator_class = str_replace( '-', ' ', $file_name );
41 $operator_class = str_replace( ' ', '_', ucwords( $operator_class ) );
42 $operator_class = "Sellkit\Admin\Notices\\{$operator_class}";
43
44 if ( ! class_exists( $operator_class ) || 'notice-base' === $file_name ) {
45 continue;
46 }
47
48 $notice = new $operator_class();
49
50 if ( $notice->is_valid() ) {
51 add_action( 'admin_notices', [ $notice, 'notice_content_wrapper' ], $notice->priority() );
52 }
53 }
54 }
55
56 /**
57 * Dismiss notice handler.
58 *
59 * @since 1.1.0
60 */
61 public function dismiss_notice() {
62 check_ajax_referer( 'sellkit_admin', 'nonce' );
63
64 $new_notice_key = ! empty( $_POST['key'] ) ? sanitize_text_field( wp_unslash( $_POST['key'] ) ) : '';
65 $dismissed_notices = sellkit_get_option( 'dismissed_notices' );
66 $dismissed_notices = empty( $dismissed_notices ) ? [] : $dismissed_notices;
67 $new_dismissed_notices = array_merge( $dismissed_notices, [ $new_notice_key ] );
68
69 sellkit_update_option( 'dismissed_notices', array_filter( array_unique( $new_dismissed_notices ) ) );
70 }
71 }
72
73 new Sellkit_Notices();
74