PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.9.11
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.9.11
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.9.11, at admin/notices/class-merchant-notice.php

129 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 * 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 * The single class instance.
39 *
40 */
41 private static $instance = null;
42
43 /**
44 * Instance.
45 *
46 * @return Merchant_Notice
47 */
48 public static function instance() {
49 if ( is_null( self::$instance ) ) {
50 self::$instance = new self();
51 }
52 return self::$instance;
53 }
54
55 /**
56 * Constructor
57 *
58 * @return void
59 */
60 public function __construct() {
61 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
62 add_action( 'admin_notices', array( $this, 'notice' ), 20 );
63 add_action( 'admin_init', array( $this, 'dimiss_notice' ), 0 );
64 }
65
66 /**
67 * Enqueue admin scripts
68 *
69 * @return void
70 */
71 public function admin_enqueue_scripts() {
72 wp_enqueue_style( 'merchant-notices', MERCHANT_URI . '/assets/css/admin/notices.min.css', array(), MERCHANT_VERSION, 'all' );
73 }
74
75 /**
76 * Notice.
77 *
78 * @return void
79 */
80 public function notice() {
81 $user_id = get_current_user_id();
82 $dismissed_notice = get_user_meta( $user_id, $this->id . '_dismiss', true ) ? true : false;
83
84 if( $this->only_free && defined( 'MERCHANT_PRO_VERSION' ) ) {
85 return;
86 }
87
88 if ( $dismissed_notice ) {
89 return;
90 }
91
92 // Display Conditions
93 global $hook_suffix;
94
95 if( ! in_array( $hook_suffix, $this->display_conditions, true ) ) {
96 return;
97 }
98
99 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
100 if( $hook_suffix === 'edit.php' && ! isset( $_GET[ 'post_type' ] ) ) {
101 return;
102 }
103
104 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
105 if( $hook_suffix === 'edit.php' && ( isset( $_GET[ 'post_type' ] ) && $_GET[ 'post_type' ] !== 'product' ) ) {
106 return;
107 }
108
109 $this->notice_markup();
110 }
111
112 /**
113 * Notice HTML markup.
114 *
115 */
116 public function notice_markup() {}
117
118 /**
119 * Dismiss notice permanently
120 *
121 * @return void
122 */
123 public function dimiss_notice() {
124 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
125 if ( isset( $_GET[$this->id . '_dismiss'] ) && '1' === $_GET[$this->id . '_dismiss'] ) {
126 add_user_meta( get_current_user_id(), $this->id . '_dismiss', 'true', true );
127 }
128 }
129 }