PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.9.14
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.9.14
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / Admin.php

Admin.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.14, at includes/Admin.php

167 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WP Admin Class
4 * conditionally loads classes for WP Admin.
5 *
6 * @author Paul Kilmurray <paul@kilbot.com.au>
7 *
8 * @see http://www.wcpos.com
9 * @package WCPOS\WooCommercePOS
10 */
11
12 namespace WCPOS\WooCommercePOS;
13
14 use Automattic\WooCommerce\Admin\PageController;
15 use WCPOS\WooCommercePOS\Admin\Analytics;
16 use WCPOS\WooCommercePOS\Admin\Notices;
17 use WCPOS\WooCommercePOS\Admin\Orders\HPOS_List_Orders;
18 use WCPOS\WooCommercePOS\Admin\Orders\HPOS_Single_Order;
19 use WCPOS\WooCommercePOS\Admin\Orders\List_Orders;
20 use WCPOS\WooCommercePOS\Admin\Orders\Single_Order;
21 use WCPOS\WooCommercePOS\Admin\Permalink;
22 use WCPOS\WooCommercePOS\Admin\Plugins;
23 use WCPOS\WooCommercePOS\Admin\Products\List_Products;
24 use WCPOS\WooCommercePOS\Admin\Products\Single_Product;
25 use WCPOS\WooCommercePOS\Admin\Settings;
26 use WCPOS\WooCommercePOS\Admin\Templates\Single_Template;
27 use WP_Screen;
28
29 /**
30 * Admin class.
31 */
32 class Admin {
33 /**
34 * POS Menu IDs.
35 *
36 * @var string[] Unique menu identifier.
37 */
38 private $menu_ids = array();
39
40 /**
41 * Registered screen handlers.
42 *
43 * @var array
44 */
45 private $screen_handlers = array();
46
47 /**
48 * Constructor.
49 *
50 * NOTE: WordPress fires the admin_menu hook before the admin_init.
51 * 1. admin_menu
52 * 2. admin_init
53 * 3. current_screen
54 *
55 * We need admin_menu at priority 5 so that we can hook the Analytics menu before WooCommerce.
56 */
57 public function __construct() {
58 add_action( 'admin_menu', array( $this, 'admin_menu' ), 5 );
59 add_action( 'admin_init', array( $this, 'init' ) );
60 add_action( 'current_screen', array( $this, 'current_screen' ) );
61
62 // register the screen handlers.
63 $this->screen_handlers = array(
64 'options-permalink' => Permalink::class,
65 'product' => Single_Product::class,
66 'edit-product' => List_Products::class,
67 'shop_order' => Single_Order::class,
68 'edit-shop_order' => List_Orders::class,
69 'plugins' => Plugins::class,
70 'wcpos_template' => Single_Template::class,
71 'woocommerce_page_wc-orders' => array( $this, 'handle_wc_hpos_orders_screen' ),
72 'woocommerce_page_wc-admin' => array( $this, 'handle_wc_analytics_screen' ),
73 );
74 }
75
76 /**
77 * Load admin subclasses.
78 */
79 public function init(): void {
80 new Notices();
81 }
82
83 /**
84 * Fires before the administration menu loads in the admin.
85 */
86 public function admin_menu(): void {
87 $menu = new Admin\Menu();
88 $this->menu_ids = array(
89 'toplevel' => $menu->toplevel_screen_id,
90 'settings' => $menu->settings_screen_id,
91 );
92
93 // Add the settings screen using the WCPOS menu ID.
94 $this->screen_handlers[ $this->menu_ids['settings'] ] = Settings::class;
95 }
96
97 /**
98 * Conditionally load subclasses based on admin screen.
99 *
100 * @TODO - I need to register the instances to allow remove_action/remove_filter.
101 *
102 * @param WP_Screen $current_screen Current screen object.
103 */
104 public function current_screen( $current_screen ): void {
105 /*
106 * Backwards compatibility for WCPOS Pro 1.4.2 and below.
107 * DO NOT USE THIS!
108 *
109 * @TODO: Remove in WCPOS 2.0.0.
110 */
111 $this->screen_handlers['product'] = apply_filters( 'woocommerce_pos_single_product_admin_class', Single_Product::class );
112
113 /**
114 * Filters the screen handlers for WCPOS admin screens.
115 *
116 * @hook woocommerce_pos_admin_screen_handlers
117 *
118 * @since 1.4.10
119 *
120 * @param array $handlers Associative array of screen IDs and their corresponding handlers.
121 * Handler can be a class name or a callback array.
122 * @param WP_Screen $current_screen The current WP_Screen object being loaded in the admin.
123 */
124 $handlers = apply_filters( 'woocommerce_pos_admin_screen_handlers', $this->screen_handlers, $current_screen );
125
126 // Check if the current screen has a handler.
127 if ( isset( $handlers[ $current_screen->id ] ) ) {
128 $handler = $handlers[ $current_screen->id ];
129
130 if ( \is_array( $handler ) && method_exists( $handler[0], $handler[1] ) ) {
131 \call_user_func( $handler );
132 } elseif ( class_exists( $handler ) ) {
133 new $handler();
134 }
135 }
136 }
137
138 /**
139 * Handle WooCommerce HPOS orders screen.
140 */
141 public function handle_wc_hpos_orders_screen(): void {
142 if ( isset( $_GET['action'] ) && 'edit' === $_GET['action'] ) {
143 new HPOS_Single_Order();
144 } else {
145 new HPOS_List_Orders();
146 }
147 }
148
149 /**
150 * Handle WooCommerce analytics screen.
151 */
152 public function handle_wc_analytics_screen(): void {
153 if ( class_exists( '\Automattic\WooCommerce\Admin\PageController' ) ) {
154 $wc_admin_page_controller = PageController::get_instance();
155 if ( $wc_admin_page_controller ) {
156 $wc_admin_current_page = $wc_admin_page_controller->get_current_page();
157 $id = $wc_admin_current_page['id'] ?? null;
158 $parent = $wc_admin_current_page['parent'] ?? null;
159
160 if ( 'woocommerce-analytics' === $id || 'woocommerce-analytics' === $parent ) {
161 new Analytics();
162 }
163 }
164 }
165 }
166 }
167