PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.10.4
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.10.4
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / admin / notices / class-merchant-notice.php

class-merchant-notice.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.10.4, at admin/notices/class-merchant-notice.php

161 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Notice main class.
4 *
5 */
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly
9 }
10
11 class Merchant_Notice {
12
13 /**
14 * The notice ID.
15 *
16 */
17 public $id = '';
18
19 /**
20 * Display conditions.
21 *
22 */
23 public $display_conditions = array(
24 'woocommerce_page_wc-settings',
25 'index.php',
26 'plugins.php',
27 'edit.php',
28 'plugin-install.php',
29 );
30
31 /**
32 * Control if notice is only for free version.
33 *
34 */
35 public $only_free = false;
36
37 /**
38 * End date target.
39 *
40 */
41 public $end_date_target = '';
42
43 /**
44 * The single class instance.
45 *
46 */
47 private static $instance = null;
48
49 /**
50 * Instance.
51 *
52 * @return Merchant_Notice
53 */
54 public static function instance() {
55 if ( is_null( self::$instance ) ) {
56 self::$instance = new self();
57 }
58 return self::$instance;
59 }
60
61 /**
62 * Constructor
63 *
64 * @return void
65 */
66 public function __construct() {
67 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
68 add_action( 'admin_notices', array( $this, 'notice' ), 20 );
69 add_action( 'admin_init', array( $this, 'dimiss_notice' ), 0 );
70 }
71
72 /**
73 * Enqueue admin scripts
74 *
75 * @return void
76 */
77 public function admin_enqueue_scripts() {
78 wp_enqueue_style( 'merchant-notices', MERCHANT_URI . '/assets/css/admin/notices.min.css', array(), MERCHANT_VERSION, 'all' );
79 }
80
81 /**
82 * Get notice dismiss status.
83 *
84 */
85 public function is_notice_dismissed() {
86 $user_id = get_current_user_id();
87
88 return get_user_meta( $user_id, $this->id . '_dismiss', true ) ? true : false;
89 }
90
91 /**
92 * Has end date passed.
93 *
94 * @return bool
95 */
96 public function has_end_date_passed() {
97 if ( empty( $this->end_date_target ) ) {
98 return false;
99 }
100
101 $end_date = strtotime( $this->end_date_target );
102 $current_date = time();
103
104 return $current_date > $end_date;
105 }
106
107 /**
108 * Notice.
109 *
110 * @return void
111 */
112 public function notice() {
113 $dismissed_notice = $this->is_notice_dismissed();
114 $has_end_date_passed = $this->has_end_date_passed();
115
116 if( $this->only_free && defined( 'MERCHANT_PRO_VERSION' ) ) {
117 return;
118 }
119
120 if ( $dismissed_notice || $has_end_date_passed ) {
121 return;
122 }
123
124 // Display Conditions
125 global $hook_suffix;
126
127 if( ! in_array( $hook_suffix, $this->display_conditions, true ) ) {
128 return;
129 }
130
131 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
132 if( $hook_suffix === 'edit.php' && ! isset( $_GET[ 'post_type' ] ) ) {
133 return;
134 }
135
136 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
137 if( $hook_suffix === 'edit.php' && ( isset( $_GET[ 'post_type' ] ) && $_GET[ 'post_type' ] !== 'product' ) ) {
138 return;
139 }
140
141 $this->notice_markup();
142 }
143
144 /**
145 * Notice HTML markup.
146 *
147 */
148 public function notice_markup() {}
149
150 /**
151 * Dismiss notice permanently
152 *
153 * @return void
154 */
155 public function dimiss_notice() {
156 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
157 if ( isset( $_GET[$this->id . '_dismiss'] ) && '1' === $_GET[$this->id . '_dismiss'] ) {
158 add_user_meta( get_current_user_id(), $this->id . '_dismiss', 'true', true );
159 }
160 }
161 }