Skip to content

Commit

Permalink
add filter to allow extending the list of post content blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankaegy committed Mar 21, 2024
1 parent d969294 commit 2ae518c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docs/reference-guides/filters/block-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,24 @@ wp.hooks.addFilter(
```


### `editor.postContentBlockTypes`

Used to modify the list of blocks that should be enabled even when used inside a locked template. Any block that saves data to a post should be added here. Examples of this are the post featured image block. Which often gets used in templates but should still allow selecting the image even when the template is locked.

_Example:_

```js
const addExampleBlockToPostContentBlockTypes = ( blockTypes ) => {
return [ ...blockTypes, 'namespace/example' ];
};

wp.hooks.addFilter(
'editor.postContentBlockTypes',
'my-plugin/post-content-block-types',
addExampleBlockToPostContentBlockTypes
);
```

## Removing Blocks

### Using a deny list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import { useSelect, useDispatch } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { useEffect } from '@wordpress/element';
import { applyFilters } from '@wordpress/hooks';

const PAGE_CONTENT_BLOCKS = [
const PAGE_CONTENT_BLOCKS = applyFilters( 'editor.postContentBlockTypes', [
'core/post-title',
'core/post-featured-image',
'core/post-content',
];
] );

function useDisableNonPageContentBlocks() {
const contentIds = useSelect( ( select ) => {
Expand Down

0 comments on commit 2ae518c

Please sign in to comment.