* UPdate to new registration API

* conditionally add path to Overview

* add comment

* change to is_top_level
This commit is contained in:
Paul Sealock 2020-10-08 10:10:37 +13:00 committed by GitHub
parent 90cad8c945
commit a4e8f6996c
2 changed files with 31 additions and 20 deletions

View File

@ -112,15 +112,19 @@ class Analytics {
* Registers report pages.
*/
public function register_pages() {
$overview_page = array(
'id' => 'woocommerce-analytics',
'title' => __( 'Analytics', 'woocommerce-admin' ),
'path' => '/analytics/overview',
'icon' => 'dashicons-chart-bar',
'position' => 56, // After WooCommerce & Product menu items.
);
if ( class_exists( '\Automattic\WooCommerce\Navigation\Menu' ) ) {
unset( $overview_page['path'] );
}
$report_pages = array(
array(
'id' => 'woocommerce-analytics',
'title' => __( 'Analytics', 'woocommerce-admin' ),
'path' => '/analytics/overview',
'path' => '/analytics/overview',
'icon' => 'dashicons-chart-bar',
'position' => 56, // After WooCommerce & Product menu items.
),
$overview_page,
array(
'id' => 'woocommerce-analytics-overview',
'title' => __( 'Overview', 'woocommerce-admin' ),

View File

@ -439,14 +439,19 @@ class PageController {
);
if ( method_exists( '\Automattic\WooCommerce\Navigation\Menu', 'add_category' ) ) {
\Automattic\WooCommerce\Navigation\Menu::add_category(
array(
'id' => $options['id'],
'title' => $options['title'],
'capability' => $options['capability'],
'url' => $options['path'],
)
$category_options = array(
'id' => $options['id'],
'title' => $options['title'],
'capability' => $options['capability'],
'url' => $options['path'],
'is_top_level' => true,
);
// If there is no path option, remove url because its a parent category item.
if ( 'wc-admin&path=' === $options['path'] ) {
unset( $category_options['url'] );
}
\Automattic\WooCommerce\Navigation\Menu::add_category( $category_options );
}
} else {
$parent_path = $this->get_path_from_id( $options['parent'] );
@ -461,13 +466,15 @@ class PageController {
);
if ( method_exists( '\Automattic\WooCommerce\Navigation\Menu', 'add_item' ) ) {
$top_level_ids = array( 'woocommerce-home', 'woocommerce-analytics-customers' );
\Automattic\WooCommerce\Navigation\Menu::add_item(
array(
'id' => $options['id'],
'parent' => $options['parent'],
'title' => $options['title'],
'capability' => $options['capability'],
'url' => $options['path'],
'id' => $options['id'],
'parent' => $options['parent'],
'title' => $options['title'],
'capability' => $options['capability'],
'url' => $options['path'],
'is_top_level' => in_array( $options['id'], $top_level_ids, true ),
)
);
}