From d94f69d11436b0fbd46ae3e6e7db899aa4c405b7 Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Fri, 17 Nov 2017 17:00:48 -0700 Subject: [PATCH] Set up the dashboard class to load the network order widget on network admin --- includes/admin/class-wc-admin-dashboard.php | 16 ++++++++++++++-- includes/admin/class-wc-admin.php | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/includes/admin/class-wc-admin-dashboard.php b/includes/admin/class-wc-admin-dashboard.php index dd9b4b03e88..4860f1c54c9 100644 --- a/includes/admin/class-wc-admin-dashboard.php +++ b/includes/admin/class-wc-admin-dashboard.php @@ -25,7 +25,12 @@ class WC_Admin_Dashboard { public function __construct() { // Only hook in admin parts if the user has admin access if ( current_user_can( 'view_woocommerce_reports' ) || current_user_can( 'manage_woocommerce' ) || current_user_can( 'publish_shop_orders' ) ) { - add_action( 'wp_dashboard_setup', array( $this, 'init' ) ); + // If on network admin, only load the widget that works in that context and skip the rest. + if ( is_multisite() && is_network_admin() ) { + add_action( 'wp_network_dashboard_setup', array( $this, 'register_network_order_widget' ) ); + } else { + add_action( 'wp_dashboard_setup', array( $this, 'init' ) ); + } } } @@ -40,10 +45,17 @@ class WC_Admin_Dashboard { // Network Order Widget. if ( is_multisite() ) { - wp_add_dashboard_widget( 'woocommerce_network_orders', __( 'WooCommerce network orders', 'woocommerce' ), array( $this, 'network_orders' ) ); + $this->register_network_order_widget(); } } + /** + * Register the network order dashboard widget. + */ + public function register_network_order_widget() { + wp_add_dashboard_widget( 'woocommerce_network_orders', __( 'WooCommerce network orders', 'woocommerce' ), array( $this, 'network_orders' ) ); + } + /** * Get top seller from DB. * @return object diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index 007c974f7b5..bab0a82db55 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -96,6 +96,7 @@ class WC_Admin { switch ( $screen->id ) { case 'dashboard' : + case 'dashboard-network' : include( 'class-wc-admin-dashboard.php' ); break; case 'options-permalink' :