-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
492 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* @author Paul Kilmurray <[email protected]> | ||
* | ||
* @see http://www.wcpos.com | ||
* @package WCPOS\Admin | ||
*/ | ||
|
||
namespace WCPOS\WooCommercePOS; | ||
|
@@ -23,23 +24,43 @@ | |
use WCPOS\WooCommercePOS\Admin\Products\List_Products; | ||
use WCPOS\WooCommercePOS\Admin\Products\Single_Product; | ||
use WCPOS\WooCommercePOS\Admin\Settings; | ||
use WCPOS\WooCommercePOS\Admin\Updaters\Pro_Plugin_Updater; | ||
|
||
/** | ||
* Admin class. | ||
*/ | ||
class Admin { | ||
/** | ||
* @vars string Unique menu identifier | ||
* POS Menu IDs. | ||
* | ||
* @var string[] Unique menu identifier. | ||
*/ | ||
private $menu_ids = array(); | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* NOTE: WordPress fires the admin_menu hook before the admin_init. | ||
* 1. admin_menu | ||
* 2. admin_init | ||
* 3. current_screen | ||
* | ||
* We need admin_menu at priority 5 so that we can hook the Analytics menu before WooCommerce. | ||
*/ | ||
public function __construct() { | ||
$this->init(); | ||
// NOTE: The admin_menu needs to hook the Analytics menu before WooCommerce calls the admin_menu hook. | ||
add_action( 'admin_menu', array( $this, 'admin_menu' ), 5 ); | ||
add_action( 'admin_init', array( $this, 'init' ) ); | ||
add_action( 'current_screen', array( $this, 'current_screen' ) ); | ||
} | ||
|
||
/** | ||
* Load admin subclasses. | ||
*/ | ||
public function init(): void { | ||
new Notices(); | ||
new Pro_Plugin_Updater(); | ||
} | ||
|
||
/** | ||
* Fires before the administration menu loads in the admin. | ||
*/ | ||
|
@@ -52,14 +73,14 @@ public function admin_menu(): void { | |
} | ||
|
||
/** | ||
* Conditionally load subclasses. | ||
* Conditionally load subclasses based on admin screen. | ||
* | ||
* @param $current_screen | ||
* @param \WP_Screen $current_screen Current screen object. | ||
*/ | ||
public function current_screen( $current_screen ): void { | ||
$action = $_GET['action'] ?? ''; | ||
|
||
// Main switch for screen IDs | ||
// Main switch for screen IDs. | ||
switch ( $current_screen->id ) { | ||
case 'options-permalink': | ||
new Permalink(); | ||
|
@@ -76,14 +97,14 @@ public function current_screen( $current_screen ): void { | |
return; | ||
case 'shop_order': | ||
new Single_Order(); | ||
|
||
return; | ||
case 'edit-shop_order': | ||
new List_Orders(); | ||
|
||
return; | ||
case 'woocommerce_page_wc-orders': | ||
if ('edit' === $action) { | ||
if ( 'edit' === $action ) { | ||
new HPOS_Single_Order(); | ||
} else { | ||
new HPOS_List_Orders(); | ||
|
@@ -95,14 +116,14 @@ public function current_screen( $current_screen ): void { | |
|
||
return; | ||
default: | ||
// Check if the current screen matches a custom setting page ID | ||
if ($this->is_woocommerce_pos_setting_page($current_screen)) { | ||
// Check if the current screen matches a custom setting page ID. | ||
if ( $this->is_woocommerce_pos_setting_page( $current_screen ) ) { | ||
new Settings(); | ||
|
||
return; | ||
} | ||
// Check if the current screen is for WooCommerce Analytics | ||
if ($this->is_woocommerce_analytics($current_screen)) { | ||
// Check if the current screen is for WooCommerce Analytics. | ||
if ( $this->is_woocommerce_analytics( $current_screen ) ) { | ||
new Analytics(); | ||
|
||
return; | ||
|
@@ -113,35 +134,27 @@ public function current_screen( $current_screen ): void { | |
/** | ||
* Check if the current screen matches the POS setting page ID. | ||
* | ||
* @param mixed $current_screen | ||
* @param \WP_Screen $current_screen Current screen object. | ||
*/ | ||
private function is_woocommerce_pos_setting_page($current_screen) { | ||
return \array_key_exists('settings', $this->menu_ids) && $this->menu_ids['settings'] === $current_screen->id; | ||
private function is_woocommerce_pos_setting_page( $current_screen ) { | ||
return \array_key_exists( 'settings', $this->menu_ids ) && $this->menu_ids['settings'] === $current_screen->id; | ||
} | ||
|
||
/** | ||
* Check if the current screen is for WooCommerce Analytics. | ||
* | ||
* @param mixed $current_screen | ||
* @param \WP_Screen $current_screen Current screen object. | ||
*/ | ||
private function is_woocommerce_analytics($current_screen) { | ||
if (class_exists('\Automattic\WooCommerce\Admin\PageController')) { | ||
private function is_woocommerce_analytics( $current_screen ) { | ||
if ( class_exists( '\Automattic\WooCommerce\Admin\PageController' ) ) { | ||
$wc_admin_page_controller = PageController::get_instance(); | ||
$wc_admin_current_page = $wc_admin_page_controller->get_current_page(); | ||
$id = $wc_admin_current_page['id'] ?? null; | ||
$parent = $wc_admin_current_page['parent'] ?? null; | ||
$id = $wc_admin_current_page['id'] ?? null; | ||
$parent = $wc_admin_current_page['parent'] ?? null; | ||
|
||
return 'woocommerce-analytics' === $id || 'woocommerce-analytics' === $parent; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
||
/** | ||
* Load admin subclasses. | ||
*/ | ||
private function init(): void { | ||
new Notices(); | ||
} | ||
} |
Oops, something went wrong.