-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add filter to allow extending the list of post content blocks #60068
Add filter to allow extending the list of post content blocks #60068
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +21 B (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Thanks for the PR.
Right now the only place where this feature is used is when editing a page in the site editor or post editor, so I'm wondering if the filter should be called editor.pageContentBlockTypes
(page instead of post)?
@noisysocks the post editor of posts and for that manner all custom post types that use the block editor also supports the template preview :) I'm very open to alternative naming. But I think pages is incorrect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough then 👍
2ae518c
to
e19f1bb
Compare
…ess#60068) Co-authored-by: fabiankaegy <[email protected]> Co-authored-by: noisysocks <[email protected]> Co-authored-by: Mamaduka <[email protected]>
const CONTENT_ONLY_BLOCKS = [ | ||
'core/post-content', | ||
'core/post-featured-image', | ||
const CONTENT_ONLY_BLOCKS = applyFilters( 'editor.postContentBlockTypes', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I'm not a big fan of this filter. I think ultimately, this is probably better as a property of the block. That said, it's hard to make it a property of the block because it doesn't really make sense in a generic block editor context. It's a WP specific property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im more than happy to experiment more with other approaches before this gets merged to core.
I took this route because @noisysocks recommended we go with this approach over having another block support.
I'm not at all set on approach here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm hesitant to have this feature escape @wordpress/editor
. It's very WP Admin specific.
…ess#60068) Co-authored-by: fabiankaegy <[email protected]> Co-authored-by: noisysocks <[email protected]> Co-authored-by: Mamaduka <[email protected]>
Dev Note Draft:Add filter to modify the list of post content block typesWhen WordPress renders a post/page's template at the same time as the content, most template blocks are disabled/locked. However, some blocks, like the Post Title, Post Content, and Post Featured Image, still allow users to edit the content within them. They get rendered in the WordPress 6.6 now adds a filter to modify this list of blocks that should get the import { addFilter } from '@wordpress/hooks';
function addCustomPostContentBlockTypes( blockTypes ) {
return [ ...blockTypes, 'namespace/hello-world' ];
}
addFilter(
'editor.postContentBlockTypes',
'namespace/add-custom-post-content-block-types',
addCustomPostContentBlockTypes
); Note: It is important that only settings that store their data in custom ways are exposed when rendered in this |
What?
Add a filter to allow extending the hardcoded list of post content blocks.
Closing: #59290
Why?
This list is used to determine which blocks should allow editing their content even when displayed in a locked template. an example of this is the post featured image block. When building custom blocks that save to a custom meta field for example is is crucial to also allow this kind of experience where the field can be edited even when the block is used outside of the post content in the template.
How?
By adding a filter that allows you to change the list of block names that should be enabled.