From 511ad4f617d2a2626a870f36358d8221fc9cec90 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Tue, 7 Mar 2023 10:47:23 -0500 Subject: [PATCH 1/2] Add examples for remove admin panels. This also updates the code to use ES modules instead of accesing the wp global. --- .../plugin-document-setting-panel.md | 65 +++++++++++++++++-- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/docs/reference-guides/slotfills/plugin-document-setting-panel.md b/docs/reference-guides/slotfills/plugin-document-setting-panel.md index fcec1d4344354c..48ea60845f117c 100644 --- a/docs/reference-guides/slotfills/plugin-document-setting-panel.md +++ b/docs/reference-guides/slotfills/plugin-document-setting-panel.md @@ -33,15 +33,68 @@ registerPlugin( 'plugin-document-setting-panel-demo', { ## Accessing a panel programmatically +Core and custom panels can be access programmatically using their panel name. The core panel names are: + +- Summary Panel: `post-status` +- Categories Panel: `taxonomy-panel-category` +- Tags Panel: `taxonomy-panel-post_tag` +- Featured Image Panel: `featured-image` +- Excerpt Panel: `post-excerpt` +- DiscussionPanel: `discussion-panel` + Custom panels are namespaced with the plugin name that was passed to `registerPlugin`. -In order to access the panels using function such as `wp.data.dispatch( 'core/edit-post' ).toggleEditorPanelOpened` or `wp.data.dispatch( 'core/edit-post' ).toggleEditorPanelEnabled` be sure to prepend the namespace. +In order to access the panels using function such as `toggleEditorPanelOpened` or `toggleEditorPanelEnabled` be sure to prepend the namespace. -To programmatically toggle the custom panel added in the example above, use the following: +To programmatically toggle panels, use the following: ```js -wp.data - .dispatch( 'core/edit-post' ) - .toggleEditorPanelOpened( - 'plugin-document-setting-panel-demo/custom-panel' +import { useDispatch } from '@wordpress/data'; +import { store as editPostStore } from '@wordpress/edit-post'; + +const Example = () => { + const { toggleEditorPanelOpened } = useDispatch( editPostStore ); + return ( + + ); +}; +``` + +It is also possible to remove panels from the admin using the `removeEditorPanel` function passing the name of the registered panel. + +```js +import { useDispatch } from '@wordpress/data'; +import { store as editPostStore } from '@wordpress/edit-post'; + +const Example = () => { + const { removeEditorPanel } = useDispatch( editPostStore ); + return ( + ); +}; ``` From 63273e17cffe267a4f6ffa5f11048df365f2ab34 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Tue, 7 Mar 2023 15:44:08 -0500 Subject: [PATCH 2/2] Updates per code review. --- .../reference-guides/slotfills/plugin-document-setting-panel.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference-guides/slotfills/plugin-document-setting-panel.md b/docs/reference-guides/slotfills/plugin-document-setting-panel.md index 48ea60845f117c..76e077056abd63 100644 --- a/docs/reference-guides/slotfills/plugin-document-setting-panel.md +++ b/docs/reference-guides/slotfills/plugin-document-setting-panel.md @@ -72,7 +72,7 @@ const Example = () => { }; ``` -It is also possible to remove panels from the admin using the `removeEditorPanel` function passing the name of the registered panel. +It is also possible to remove panels from the admin using the `removeEditorPanel` function by passing the name of the registered panel. ```js import { useDispatch } from '@wordpress/data';