admin管理员组文章数量:1384181
I created few custom blocks which work just fine.
I plan for these blocks to have common attributes and I'm using the blocks.registerBlockType
filter to add an attribute, here is my code:
import { blocksWithSharedAttributes } from '../blocks-wth-shared-attributes.jsx'; // an array of names of custom blocks.
const { addFilter } = wp.hooks;
const addToggleRenderBlockAttribute = ( settings, name ) => {
if ( ! blocksWithSharedAttributes.includes( name ) ) {
return settings; // This callback returns here. :(
}
settings.attributes = Object.assign( settings.attributes, {
toggleBlockRender: {
type: 'boolean',
default: false,
},
} );
return settings;
};
addFilter( 'blocks.registerBlockType', 'someNamespace/attribute/toggleBlockRender', addToggleRenderBlockAttribute );
The problem I'm facing is that the name
argument doesn't have any of the custom blocks I created and due to that the callback returns at line 7.
The name
argument only has core/
blocks. How can I make custom blocks appear in the filter?
I created few custom blocks which work just fine.
I plan for these blocks to have common attributes and I'm using the blocks.registerBlockType
filter to add an attribute, here is my code:
import { blocksWithSharedAttributes } from '../blocks-wth-shared-attributes.jsx'; // an array of names of custom blocks.
const { addFilter } = wp.hooks;
const addToggleRenderBlockAttribute = ( settings, name ) => {
if ( ! blocksWithSharedAttributes.includes( name ) ) {
return settings; // This callback returns here. :(
}
settings.attributes = Object.assign( settings.attributes, {
toggleBlockRender: {
type: 'boolean',
default: false,
},
} );
return settings;
};
addFilter( 'blocks.registerBlockType', 'someNamespace/attribute/toggleBlockRender', addToggleRenderBlockAttribute );
The problem I'm facing is that the name
argument doesn't have any of the custom blocks I created and due to that the callback returns at line 7.
The name
argument only has core/
blocks. How can I make custom blocks appear in the filter?
1 Answer
Reset to default 1I found the solution.
addFilter( 'blocks.registerBlockType )
needs to be called before the call to registerBlockType
.
本文标签: hooksHow to extend custom (noncore) blocks
版权声明:本文标题:hooks - How to extend custom (non-core) blocks? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744486561a2608483.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论