Skip to content

Commit

Permalink
add filter to allow extending the list of post content blocks (#60068)
Browse files Browse the repository at this point in the history
Co-authored-by: fabiankaegy <[email protected]>
Co-authored-by: noisysocks <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
4 people authored Mar 27, 2024
1 parent 9cb88aa commit f85d5c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 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,13 +4,14 @@
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 CONTENT_ONLY_BLOCKS = [
'core/post-content',
'core/post-featured-image',
const CONTENT_ONLY_BLOCKS = applyFilters( 'editor.postContentBlockTypes', [
'core/post-title',
'core/post-featured-image',
'core/post-content',
'core/template-part',
];
] );

/**
* Component that when rendered, makes it so that the site editor allows only
Expand Down

0 comments on commit f85d5c9

Please sign in to comment.