Better API for toggling default functionality in blocks. #12414
Labels
Needs Technical Feedback
Needs testing from a developer perspective.
[Type] Question
Questions about the design or development of the editor.
The challenge
One of the first things I usually do when developing a WordPress theme is to deduct functionality that let content creators create inconsistent layouts/typography. As a designer I'm used to see layouts/typography become inconsistent because the content creator have too much freedom in the editor. Common things we see is blog posts with center aligned text, where all the other blog posts are left aligned. Inconsistency in image sizes. And texts that are all bold where bold should only be used to emphasise words.
E.g. if I want to disable captions on images in Gutenberg. I have to duplicate the core block and then make my changes in the new blocks to remove functionality I don't want. The same matter is with alignments on images, paragraph, headers, and so on. I believe this could be done in a much easier way. Also in a way that could make it better to reuse existing blocks to create new blocks by using
InnerBlocks
.Suggested solution
I haven't really thought about in this solution would be how to globally toggle functionality. For UX and design purposes mentioned above it would be nice to be able to disable block settings like alignment, text styles, drop-cap, image editing, image link settings, etc. in a similar way that
add_theme_support( 'disable-custom-colors' );
andadd_theme_support( 'disable-custom-font-sizes' );
do.A possible solution would be adding new attributes to core blocks for disabling default functionality. Example: To toggle captions on images we add a
disableCaption
attribute to the core image block, then we can conditionally render the caption:Then block filters can be used to toggle default functionality for the block.
This would also make it a lot easier to build new blocks with InnerBlocks and the Template API using existing blocks. Here is an example on how a new block could be composited (note the comments in the template):
Reviewing the suggested solution
I can see a problem with this solution is that attributes are meant to be used to extract a value of an attribute from markup, and they are not meant to work as settings for the block. A solution for this could be making a Block Settings Api that works in a similar way like attributes.
Wrapping up
I have seen other block specific issues mentioning the ability to toggle specific functionality. I can refer to them if that is wanted. I hope all this makes sense and its something we can consider. Thanks for taking WordPress to the next level :)
The text was updated successfully, but these errors were encountered: