Skip to content

Commit

Permalink
Add examples for remove admin panels. This also updates the code to u…
Browse files Browse the repository at this point in the history
…se ES modules instead of accesing the wp global.
  • Loading branch information
ryanwelcher committed Mar 7, 2023
1 parent 0771b0a commit 511ad4f
Showing 1 changed file with 59 additions and 6 deletions.
65 changes: 59 additions & 6 deletions docs/reference-guides/slotfills/plugin-document-setting-panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Button
variant="primary"
onClick={ () => {
// Toggle the Summary panel
toggleEditorPanelOpened( 'post-status' );

// Toggle the Custom Panel introduced in the example above.
toggleEditorPanelOpened(
'plugin-document-setting-panel-demo/custom-panel'
);
} }
>
Toggle Panels
</Button>
);
};
```

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 (
<Button
variant="primary"
onClick={ () => {
// Remove the Featured Image panel.
removeEditorPanel( 'featured-image' );

// Remove the Custom Panel introduced in the example above.
removeEditorPanel(
'plugin-document-setting-panel-demo/custom-panel'
);
} }
>
Toggle Panels
</Button>
);
};
```

0 comments on commit 511ad4f

Please sign in to comment.