这可以使用block filters.
首先,您需要过滤图像块的块属性,以便能够保存新项目:
const { addFilter } = wp.hooks;
function filterAttributes( settings, name ) {
if ( \'core/image\' === name && settings.attributes ) {
settings.attributes.description = {
type: \'string\',
default: \'\'
};
settings.attributes.nopin = {
type: \'boolean\',
default: false
};
}
return settings;
}
addFilter( \'blocks.registerBlockType\', \'wpse\', filterAttributes );
接下来,您需要过滤图像块的InspectorControl以添加新控件:
const { addFilter } = wp.hooks;
const { createHigherOrderComponent } = wp.compose;
const withInspectorControls = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
return (
<>
{ ( \'core/image\' !== props.name ) &&
<InspectorControls>
// YOUR CUSTOM CONTROLS GO HERE
</InspectorControls>
}
<BlockEdit { ...props } /> // THIS IS ALL OF THE OTHER CONTROLS AND CAN GO ABOVE YOUR STUFF AS WELL
</>
);
};
}, \'withInspectorControl\' );
addFilter( \'editor.BlockEdit\', \'wpse\', withInspectorControls );
您需要管理自定义控件部分,因为我不知道那里的详细信息。
希望这有帮助!