admin管理员组文章数量:1384394
I want to disable the .alignwide
and .alignfull
block alignment options (remove them from the editor UI) on the 'post' post-type only.
I have tried using this block registration filter to modify the 'supports' attribute:
function disablePostAlignwide( settings, name ) {
if ( "post" != wp.data.select('core/editor').getCurrentPostType() ) {
return settings;
}
return lodash.assign( {}, settings, {
supports: lodash.assign( {}, settings.supports, {
align: ['left', 'center', 'right'],
alignWide: false,
} ),
} );
}
wp.hooks.addFilter( 'blocks.registerBlockType', 'my-namespace', disablePostAlignwide );
This does not work because wp.data.select('core/editor').getCurrentPostType()
returns null
. I have tried adding the hook in wp.domReady
, but then the filter does not run at all, presumably because the hook has already fired.
How can I get the current post-type before the registerBlockType
hook fires?
An answer that disables the alignment options on a post-type basis via another method (i.e. PHP) would also be acceptable.
本文标签: javascriptHow can I filter block registration based on posttype (Block alignment settings)
版权声明:本文标题:javascript - How can I filter block registration based on post-type? (Block alignment settings) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744486904a2608503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论