PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.8.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.8.2
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 / classes / class-merchant-admin-menu.php

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

160 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Merchant_Admin_Menu Class.
4 */
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly
8 }
9
10 if ( ! class_exists( 'Merchant_Admin_Menu' ) ) {
11
12 class Merchant_Admin_Menu {
13
14 /**
15 * Page title.
16 */
17 public $page_title = 'Merchant';
18
19 /**
20 * Plugin slug.
21 */
22 public $plugin_slug = 'merchant';
23
24 /**
25 * Plugin capability.
26 */
27 public $capability = 'manage_options';
28
29 /**
30 * Plugin priority.
31 */
32 public $priority = 58;
33
34 /**
35 * Plugin notifications.
36 */
37 public $notifications = array();
38
39 /**
40 * The single class instance.
41 */
42 private static $instance = null;
43
44 /**
45 * Instance.
46 */
47 public static function instance() {
48 if ( is_null( self::$instance ) ) {
49 self::$instance = new self();
50 }
51 return self::$instance;
52 }
53
54 /**
55 * Constructor.
56 */
57 public function __construct() {
58
59 add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
60 add_action( 'wp_ajax_merchant_notifications_read', array( $this, 'ajax_notifications_read' ) );
61 }
62
63 /**
64 * Include required classes.
65 */
66 public function add_admin_menu() {
67
68 global $submenu;
69
70 // Dashboard
71 add_menu_page(
72 $this->page_title,
73 $this->page_title,
74 $this->capability,
75 $this->plugin_slug,
76 array( $this, 'page_dashboard' ),
77 MERCHANT_URI . 'assets/images/merchant-logo.svg',
78 $this->priority
79 );
80 }
81
82 /**
83 * Get Notifications
84 */
85 public function get_notifications() {
86 $notifications = get_transient( 'merchant_notifications' );
87
88 if ( ! empty( $notifications ) ) {
89 $this->notifications = $notifications;
90 } else {
91
92 /**
93 * Hook: merchant_changelog_api_url
94 *
95 * @since 1.0
96 */
97 $response = wp_remote_get( apply_filters( 'merchant_changelog_api_url', 'https://athemes.com/wp-json/wp/v2/notifications?theme=7103&per_page=3' ) );
98
99 if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) {
100 $this->notifications = json_decode( wp_remote_retrieve_body( $response ) );
101 set_transient( 'merchant_notifications', $this->notifications, 24 * HOUR_IN_SECONDS );
102 }
103 }
104
105 return $this->notifications;
106 }
107
108 /**
109 * Check if the latest notification is read
110 */
111 public function is_latest_notification_read() {
112
113 if ( ! isset( $this->notifications ) || empty( $this->notifications ) ) {
114 return false;
115 }
116
117 $user_id = get_current_user_id();
118 $user_read_meta = get_user_meta( $user_id, 'merchant_dashboard_notifications_latest_read', true );
119
120 $last_notification_date = strtotime( is_string( $this->notifications[0]->post_date ) ? $this->notifications[0]->post_date : '' );
121 $last_notification_date_ondb = $user_read_meta ? strtotime( $user_read_meta ) : false;
122
123 if ( ! $last_notification_date_ondb ) {
124 return false;
125 }
126
127 if ( $last_notification_date > $last_notification_date_ondb ) {
128 return false;
129 }
130
131 return true;
132 }
133
134 /**
135 * Ajax notifications.
136 */
137 public function ajax_notifications_read() {
138 check_ajax_referer( 'merchant', 'nonce' );
139
140 // Check current user capabilities
141 if ( ! current_user_can( 'manage_options' ) ) {
142 wp_send_json_error( 'You are not allowed to do this.' );
143 }
144
145 $latest_notification_date = ( isset( $_POST[ 'latest_notification_date' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'latest_notification_date' ] ) ) : false;
146
147 update_user_meta( get_current_user_id(), 'merchant_dashboard_notifications_latest_read', $latest_notification_date );
148
149 wp_send_json_success();
150 }
151
152 public function page_dashboard() {
153 require_once MERCHANT_DIR . 'admin/pages/page-dashboard.php';
154 }
155 }
156
157 Merchant_Admin_Menu::instance();
158
159 }
160