From 4775defb1fc0e8889a31f7bd822783f4061004d0 Mon Sep 17 00:00:00 2001 From: Moon Date: Tue, 18 Oct 2022 09:22:51 -0700 Subject: [PATCH] Update WooCommerce beta tester README (#35090) * Update readme * Add changelog * Add Installation section * Fix typo * Update WC Admin Test Helper dev commands * Move back Development section to README.md --- .../EXTENDING-WC-ADMIN-HELPER.md | 91 ++++++++++++ plugins/woocommerce-beta-tester/README.md | 129 ++---------------- .../update-woocommerce-beta-tester-readme | 4 + 3 files changed, 104 insertions(+), 120 deletions(-) create mode 100644 plugins/woocommerce-beta-tester/EXTENDING-WC-ADMIN-HELPER.md create mode 100644 plugins/woocommerce-beta-tester/changelog/update-woocommerce-beta-tester-readme diff --git a/plugins/woocommerce-beta-tester/EXTENDING-WC-ADMIN-HELPER.md b/plugins/woocommerce-beta-tester/EXTENDING-WC-ADMIN-HELPER.md new file mode 100644 index 00000000000..0060ed451e8 --- /dev/null +++ b/plugins/woocommerce-beta-tester/EXTENDING-WC-ADMIN-HELPER.md @@ -0,0 +1,91 @@ +## Extending + +There are two client-side filters available if you want to extend the test +helper with your own plugin's test setup code. + +This example adds a new tab: + +``` +import { addFilter } from '@wordpress/hooks'; + +const SuperSekret = () => ( + <> +

Super sekret

+

This section contains super sekret tools.

+ + +); +addFilter( + 'woocommerce_admin_test_helper_tabs', + 'wath', + ( tabs ) => [ + ...tabs, + { + name: 'super-sekret', + title: 'Super sekret', + content: , + } + ] +); +``` + +This example adds a new tool to the existing Options tab: + +``` +import { addFilter } from '@wordpress/hooks'; + +const NewTool = () => ( + <> + New tool +

Description

+ + +); +addFilter( + 'woocommerce_admin_test_helper_tab_options', + 'wath', + ( entries ) => [ + ...entries, + + ] +); +``` + +Register a REST API endpoint to perform server-side actions in the usual way: + +``` +add_action( 'rest_api_init', function() { + register_rest_route( + 'your-plugin/v1', + '/area/action', + array( + 'methods' => 'POST', + 'callback' => 'your_plugin_area_action', + 'permission_callback' => function( $request ) { + if ( ! wc_rest_check_manager_permissions( 'settings', 'edit ) ) { + return new \WP_Error( + 'woocommerce_rest_cannot_edit', + __( 'Sorry, you cannot perform this action', 'your-plugin' ) + ); + } + return true; + } + ) + ); +} ); + +function your_plugin_area_action() { + return []; +} +``` + +This would be used on the client like this: + +``` +import apiFetch from '@wordpress/api-fetch'; +... +const response = await apiFetch( { + path: '/your-plugin/v1/area/action', + method: 'POST', +} ); +``` diff --git a/plugins/woocommerce-beta-tester/README.md b/plugins/woocommerce-beta-tester/README.md index 3b36bd7fd56..65a1889ebfb 100644 --- a/plugins/woocommerce-beta-tester/README.md +++ b/plugins/woocommerce-beta-tester/README.md @@ -1,137 +1,26 @@ # WooCommerce Beta Tester -A plugin that makes it easy to test out pre-releases such as betas release canadidates and even final releases. +A plugin that makes it easy to test out pre-releases such as betas release candidates and even final releases. It also comes with WooCommerce Admin Test Helper that helps test WooCommerce Admin functionalities. -## Usage +## Installation -You can get to the settings and features from your top admin bar under the name WC Beta Tester. - -# WooCommerce Admin Test Helper - -A plugin that makes it easier to test the WooCommerce Admin plugin. +You can either install the latest version from [wp.org](https://wordpress.org/plugins/woocommerce-beta-tester/) or symlink this directory by running `ln -s ./ :path-to-your-wp-plugin-directory/woocommerce-beta-tester` ## Development To get started, run the following commands: ```text -npm install -npm start +pnpm install +pnpm run start ``` See [wp-scripts](https://github.com/WordPress/gutenberg/tree/master/packages/scripts) for more usage information. -## Extending +## Usage -There are two client-side filters available if you want to extend the test -helper with your own plugin's test setup code. +You can get to the settings and features from your top admin bar under the name WC Beta Tester. -This example adds a new tab: +For more information about WooCommerce Admin Test Helper usage, click [here](./EXTENDING-WC-ADMIN-HELPER.md). -``` -import { addFilter } from '@wordpress/hooks'; - -const SuperSekret = () => ( - <> -

Super sekret

-

This section contains super sekret tools.

- - -); -addFilter( - 'woocommerce_admin_test_helper_tabs', - 'wath', - ( tabs ) => [ - ...tabs, - { - name: 'super-sekret', - title: 'Super sekret', - content: , - } - ] -); -``` - -This example adds a new tool to the existing Options tab: - -``` -import { addFilter } from '@wordpress/hooks'; - -const NewTool = () => ( - <> - New tool -

Description

- - -); -addFilter( - 'woocommerce_admin_test_helper_tab_options', - 'wath', - ( entries ) => [ - ...entries, - - ] -); -``` - -Register a REST API endpoint to perform server-side actions in the usual way: - -``` -add_action( 'rest_api_init', function() { - register_rest_route( - 'your-plugin/v1', - '/area/action', - array( - 'methods' => 'POST', - 'callback' => 'your_plugin_area_action', - 'permission_callback' => function( $request ) { - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit ) ) { - return new \WP_Error( - 'woocommerce_rest_cannot_edit', - __( 'Sorry, you cannot perform this action', 'your-plugin' ) - ); - } - return true; - } - ) - ); -} ); - -function your_plugin_area_action() { - return []; -} -``` - -This would be used on the client like this: - -``` -import apiFetch from '@wordpress/api-fetch'; -... -const response = await apiFetch( { - path: '/your-plugin/v1/area/action', - method: 'POST', -} ); -``` - -### Deploying - -Prerequisites: - -- [Hub](https://github.com/github/hub) -- Write access to this repository - -You can create a test ZIP of the plugin using this command: - -``` -npm run build -``` - -This creates `woocommerce-admin-test-helper.zip` in the project root. - -We release the plugin using GitHub Releases. There is a script to automate this: - -0. Make sure the version is updated in `woocommerce-admin-test-helper.php` and `package.json` -1. Commit and push to `trunk` -2. Run `npm run release` -3. Make sure you provide the correct version number when prompted -4. That's it! +Run `./bin/build-zip.sh` to make a zip file. diff --git a/plugins/woocommerce-beta-tester/changelog/update-woocommerce-beta-tester-readme b/plugins/woocommerce-beta-tester/changelog/update-woocommerce-beta-tester-readme new file mode 100644 index 00000000000..ce36805e219 --- /dev/null +++ b/plugins/woocommerce-beta-tester/changelog/update-woocommerce-beta-tester-readme @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Update README to separate WooCommerce Admin Tester