Skip to content

Commit

Permalink
Sidebar: Make display of tabs filterable
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Nov 25, 2022
1 parent 511072b commit f041f13
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
18 changes: 18 additions & 0 deletions docs/reference-guides/filters/editor-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ To modify the behavior of the editor experience, WordPress exposes several APIs.

The following filters are available to extend the editor features.

### `editor.BlockInspector.showTabs`

Used to filter the display of tabs in the block inspector sidebar.

_Example:_

```js
var maybeDisableTabs = function ( blockName, showTabs ) {
return blockName === 'core/query' ? false : showTabs;
};

wp.hooks.addFilter(
'editor.BlockInspector.showTabs',
'my-plugin/maybe-disable-tabs',
maybeDisableTabs
);
```

### `editor.PostFeaturedImage.imageSize`

Used to modify the image size displayed in the Post Featured Image component. It defaults to `'post-thumbnail'`, and will fail back to the `full` image size when the specified image size doesn't exist in the media object. It's modeled after the `admin_post_thumbnail_size` filter in the classic editor.
Expand Down
16 changes: 11 additions & 5 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { useMemo, useCallback } from '@wordpress/element';
import { applyFilters } from '@wordpress/hooks';

/**
* Internal dependencies
Expand Down Expand Up @@ -175,9 +176,12 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
}, [] );

const availableTabs = useInspectorControlsTabs( blockType?.name );
const showTabs =
const showTabs = applyFilters(
'editor.BlockInspector.showTabs',
blockType?.name,
window?.__experimentalEnableBlockInspectorTabs &&
availableTabs.length > 1;
availableTabs.length > 1
);

if ( count > 1 ) {
return (
Expand Down Expand Up @@ -254,10 +258,12 @@ const BlockInspectorSingleBlock = ( {
parentBlockClientId,
} ) => {
const availableTabs = useInspectorControlsTabs( blockName );
const showTabs =
const showTabs = applyFilters(
'editor.BlockInspector.showTabs',
blockName,
window?.__experimentalEnableBlockInspectorTabs &&
availableTabs.length > 1;

availableTabs.length > 1
);
const hasBlockStyles = useSelect(
( select ) => {
const { getBlockStyles } = select( blocksStore );
Expand Down

0 comments on commit f041f13

Please sign in to comment.