From c2fe5c2cfdbc1dcdf85b0291a968e43bcb1479f4 Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Mon, 26 Oct 2020 14:26:48 -0400 Subject: [PATCH] Add navigation plugin example (https://github.com/woocommerce/woocommerce-admin/pull/5425) * Add nav items example plugin * Fix URLs * Use WP components button in example --- .../add-navigation-items/js/index.js | 23 +++++ ...rce-admin-add-navigation-items-example.php | 84 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 plugins/woocommerce-admin/docs/examples/extensions/add-navigation-items/js/index.js create mode 100644 plugins/woocommerce-admin/docs/examples/extensions/add-navigation-items/woocommerce-admin-add-navigation-items-example.php diff --git a/plugins/woocommerce-admin/docs/examples/extensions/add-navigation-items/js/index.js b/plugins/woocommerce-admin/docs/examples/extensions/add-navigation-items/js/index.js new file mode 100644 index 00000000000..cbe651c5daf --- /dev/null +++ b/plugins/woocommerce-admin/docs/examples/extensions/add-navigation-items/js/index.js @@ -0,0 +1,23 @@ +/** + * External dependencies + */ +import { __ } from '@wordpress/i18n'; +import { Button } from '@wordpress/components'; +import { registerPlugin } from "@wordpress/plugins"; +import { WooNavigationItem } from "@woocommerce/navigation"; + +const MyPlugin = () => { + const handleClick = () => { + alert( 'Menu item clicked!' ); + } + + return ( + + + + ); +}; + +registerPlugin('my-plugin', { render: MyPlugin }); diff --git a/plugins/woocommerce-admin/docs/examples/extensions/add-navigation-items/woocommerce-admin-add-navigation-items-example.php b/plugins/woocommerce-admin/docs/examples/extensions/add-navigation-items/woocommerce-admin-add-navigation-items-example.php new file mode 100644 index 00000000000..9f8a05caf65 --- /dev/null +++ b/plugins/woocommerce-admin/docs/examples/extensions/add-navigation-items/woocommerce-admin-add-navigation-items-example.php @@ -0,0 +1,84 @@ + 'example-marketing-plugin', + 'title' => 'Example Marketing Settings', + 'capability' => 'view_woocommerce_reports', + 'parent' => 'settings', + 'url' => 'https://www.google.com', + ) + ); + + \Automattic\WooCommerce\Admin\Features\Navigation\Menu::add_category( + array( + 'id' => 'example-marketing-category', + 'parent' => 'woocommerce-marketing', + 'title' => 'Example Marketing Category', + 'capability' => 'view_woocommerce_reports', + ) + ); + + \Automattic\WooCommerce\Admin\Features\Navigation\Menu::add_item( + array( + 'id' => 'example-marketing-category-child-1', + 'parent' => 'example-marketing-category', + 'title' => 'Sub Menu Child 1', + 'capability' => 'view_woocommerce_reports', + 'url' => 'https://www.google.com', + ) + ); + + \Automattic\WooCommerce\Admin\Features\Navigation\Menu::add_item( + array( + 'id' => 'example-marketing-category-child-2', + 'parent' => 'example-marketing-category', + 'title' => 'Sub Menu Child 2', + 'capability' => 'view_woocommerce_reports', + 'url' => 'https://www.google.com', + ) + ); +} +add_filter( 'admin_menu', 'add_navigation_items_register_items' );