Navigation: Change default location and add Product category items (https://github.com/woocommerce/woocommerce-admin/pull/6179)

* add product submenu items

* better check

* extesnions section

* use add_plugin_item

* htmlspecialchars_decode better

* Manually add product_brand taxonomy

* Determine if migrated items are a taxonomy or post_type. If they are, register them.

* add in_array check to register post types and taxonomies

* register a taxonomy or post_type, but not both
This commit is contained in:
Paul Sealock 2021-01-27 13:05:55 +13:00 committed by GitHub
parent 053db8512c
commit 84222b568b
4 changed files with 47 additions and 10 deletions

View File

@ -48,6 +48,7 @@
"config": "^3.2.4",
"eslint": "6.7.2",
"jest": "^24.9.0",
"prettier": "npm:wp-prettier@1.19.1",
"puppeteer": "^2.0.0"
},
"dependencies": {
@ -103,6 +104,11 @@
}
}
}
},
"prettier": {
"version": "npm:wp-prettier@1.19.1",
"resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-1.19.1.tgz",
"integrity": "sha512-mqAC2r1NDmRjG+z3KCJ/i61tycKlmADIjxnDhQab+KBxSAGbF/W7/zwB2guy/ypIeKrrftNsIYkNZZQKf3vJcg=="
}
}
},

View File

@ -134,10 +134,11 @@ class CoreMenu {
'order' => 20,
)
);
$coupon_items = Menu::get_post_type_items( 'shop_coupon', array( 'parent' => 'woocommerce-marketing' ) );
$setting_items = self::get_setting_items();
$wca_items = array();
$wca_pages = \Automattic\WooCommerce\Admin\PageController::get_instance()->get_pages();
$coupon_items = Menu::get_post_type_items( 'shop_coupon', array( 'parent' => 'woocommerce-marketing' ) );
$setting_items = self::get_setting_items();
$wca_items = array();
$wca_pages = \Automattic\WooCommerce\Admin\PageController::get_instance()->get_pages();
foreach ( $wca_pages as $page ) {
if ( ! isset( $page['nav_args'] ) ) {

View File

@ -490,11 +490,16 @@ class Menu {
public function migrate_core_child_items( $menu ) {
global $submenu;
if ( ! isset( $submenu['woocommerce'] ) ) {
if ( ! isset( $submenu['woocommerce'] ) && ! isset( $submenu['edit.php?post_type=product'] ) ) {
return;
}
foreach ( $submenu['woocommerce'] as $key => $menu_item ) {
$submenu_items = array_merge(
isset( $submenu['woocommerce'] ) ? $submenu['woocommerce'] : array(),
isset( $submenu['edit.php?post_type=product'] ) ? $submenu['edit.php?post_type=product'] : array()
);
foreach ( $submenu_items as $key => $menu_item ) {
if ( in_array( $menu_item[2], CoreMenu::get_excluded_items(), true ) ) {
// phpcs:disable
if ( ! isset( $menu_item[ self::CSS_CLASSES ] ) ) {
@ -506,21 +511,42 @@ class Menu {
continue;
}
$menu_item[2] = htmlspecialchars_decode( $menu_item[2] );
// Don't add already added items.
$callbacks = self::get_callbacks();
if ( array_key_exists( $menu_item[2], $callbacks ) ) {
continue;
}
self::add_item(
// Don't add these Product submenus because they are added elsewhere.
if ( in_array( $menu_item[2], array( 'product_importer', 'product_exporter', 'product_attributes' ), true ) ) {
continue;
}
self::add_plugin_item(
array(
'parent' => 'woocommerce-settings',
'title' => $menu_item[0],
'capability' => $menu_item[1],
'id' => sanitize_title( $menu_item[0] ),
'url' => $menu_item[2],
)
);
// Determine if migrated items are a taxonomy or post_type. If they are, register them.
$parsed_url = wp_parse_url( $menu_item[2] );
$query_string = isset( $parsed_url['query'] ) ? $parsed_url['query'] : false;
if ( $query_string ) {
$query = array();
parse_str( $query_string, $query );
if ( isset( $query['taxonomy'] ) ) {
Screen::register_taxonomy( $query['taxonomy'] );
} elseif ( isset( $query['post_type'] ) ) {
Screen::register_post_type( $query['post_type'] );
}
}
}
return $menu;

View File

@ -213,7 +213,9 @@ class Screen {
* @param string $post_type Post type to add.
*/
public static function register_post_type( $post_type ) {
self::$post_types[] = $post_type;
if ( ! in_array( $post_type, self::$post_types, true ) ) {
self::$post_types[] = $post_type;
}
}
/**
@ -222,6 +224,8 @@ class Screen {
* @param string $taxonomy Taxonomy to add.
*/
public static function register_taxonomy( $taxonomy ) {
self::$taxonomies[] = $taxonomy;
if ( ! in_array( $taxonomy, self::$taxonomies, true ) ) {
self::$taxonomies[] = $taxonomy;
}
}
}