从 WordPress 核心古腾堡块中删除属性
随着新的 WordPress 更新,核心 Gutenberg 块中添加了一些新属性,以便某些用户更轻松地自定义这些块
在上图中,您可以看到新外观的示例引用块的。例如,现在可以选择更改版式的外观以及新的“简单”样式选项。我想删除这些选项,但到目前为止我发现的唯一一件事是如何添加额外的属性以及如何完全删除块。
对于样式,我找到了获取属性的钩子,但我不知道如何修改它,因此它不显示“普通”选项:
// hide "plain" opiton inside the style tab of the quote block.
const {
addFilter,
} = wp.hooks;
addFilter(
'blocks.registerBlockType',
'jsforwp-advgb/extend-quote-block',
extendBlockQuoteBlock
);
function extendBlockQuoteBlock( settings, name ) {
if ( !settings || !settings.supports ) {
return settings;
}
if ( 'core/quote' !== name ) return settings;
console.log( settings.styles );
return settings;
}
With the new wordpress update there are some new properties that have been added to the core gutenberg blocks to make it easier for certain users to customize these blocks
In the image above you can see the example for the new looks of the quote block. For instance there is now the option to change the appearance of the typography as well as a new 'plain' option for the styles. I want to remove these options, but The only thing i have found so far is how to add extra properties nd how to remove the block entierly.
For the styles, i have found the hook to get the property, but I don't know how i can modify this so it doesn't show the "plain" option:
// hide "plain" opiton inside the style tab of the quote block.
const {
addFilter,
} = wp.hooks;
addFilter(
'blocks.registerBlockType',
'jsforwp-advgb/extend-quote-block',
extendBlockQuoteBlock
);
function extendBlockQuoteBlock( settings, name ) {
if ( !settings || !settings.supports ) {
return settings;
}
if ( 'core/quote' !== name ) return settings;
console.log( settings.styles );
return settings;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用
unregisterBlockStyle(blockName, styleVariationName)
删除块样式。无需扩展或添加过滤器到块注册,只需在 DOM 准备好防止竞争条件时使用unregisterBlockStyle
即可:参考:块编辑器手册/参考指南/块 API 参考/样式
更新: 下面是截图显示在控制台中运行
wp.blocks.unregisterBlockStyle( 'core/quote', 'plain' )
的效果。如果您希望删除排版,它与块样式不同,并且来自块支持 API,这是通过 addFilter 和 lodash allocate 完成的,以删除对您不想要的功能的支持,例如:
Block styles can be removed with
unregisterBlockStyle(blockName, styleVariationName)
. There is no need extend or add a filter to the block registration, just useunregisterBlockStyle
when the DOM is ready to prevent a race condition:Ref: Block Editor Handbook / Reference Guides / Block API Reference / Styles
Update: Below is a screenshot showing the effect of running
wp.blocks.unregisterBlockStyle( 'core/quote', 'plain' )
in the console.If you wish to remove typography, it is different to block styles and is from the block supports API, which is done with addFilter and lodash assign to remove support for the features you dont want, eg: