Wordpress 如何禁用核心块的工具栏?这可能吗?

Wordpress 如何禁用核心块的工具栏?这可能吗?,wordpress,jsx,wordpress-gutenberg,Wordpress,Jsx,Wordpress Gutenberg,我试图禁用所有核心块的工具栏,以防止编辑器不必要地格式化内容。这可能吗 我目前的做法是: wp.blocks.getBlockTypes().forEach((blockType) => { // unregister all default styles (from the right sidebar) let blockName = blockType.name; if ( blockType.hasOwnProperty('styles')) {

我试图禁用所有核心块的工具栏,以防止编辑器不必要地格式化内容。这可能吗

我目前的做法是:

wp.blocks.getBlockTypes().forEach((blockType) => {

    // unregister all default styles (from the right sidebar)

    let blockName = blockType.name;

    if ( blockType.hasOwnProperty('styles')) {
        blockType.styles.forEach( (style) => {
            wp.blocks.unregisterBlockStyle( blockName, style.name );
        });
    }     

});
我可以访问这个循环中的工具栏吗?我是否正确理解必须覆盖核心块的编辑和保存方法,可能是使用过滤器


谢谢,帕特里克,我刚刚解决了这个问题,但与预期的不同。 基本上,我的解决方案是取消注册所需的核心块,更改编辑和保存方法,然后重新注册这些块

里亚德·本格拉(Riad Benguella)的这篇博客文章帮了大忙:

下面是一个基于核心/报价块的示例:

const TextControl = wp.components.TextControl;

import './style.scss';
import './editor.scss';

wp.domReady( () => {

    let unregisteredBlock = wp.blocks.unregisterBlockType('core/quote');

    unregisteredBlock.title = 'Quotation';
    unregisteredBlock.icon = 'format-quote';

    unregisteredBlock.edit = ({ attributes, setAttributes} ) => {    

        const updateFirstValue = ( val ) => {
            setAttributes({
                value: val
            });
        };
        const updateSecondValue = ( val ) => {
            setAttributes({
                citation: val
            });
        };

        return (
            <div>
                <TextControl
                    label='Quote'
                    value={ attributes.value }
                    onChange={ updateFirstValue }
                />
                <TextControl
                    label='Citation'
                    value={ attributes.citation }
                    onChange={ updateSecondValue }
                />
            </div>
        );

    };

    unregisteredBlock.save = ( { attributes, className } ) => {
        return (
            <blockquote className={className}>
                <p>{attributes.value}</p>
                <cite>{attributes.citation}</cite>
            </blockquote>
        )
    };

    wp.blocks.registerBlockType('core/quote', unregisteredBlock);

});
const TextControl=wp.components.TextControl;
导入“/style.scss”;
导入“/editor.scss”;
wp.domReady(()=>{
让unregisteredBlock=wp.blocks.unregisterBlockType('core/quote');
unregisteredBlock.title='quote';
unregisteredBlock.icon='format quote';
unregisteredBlock.edit=({attributes,setAttributes})=>{
常量updateFirstValue=(val)=>{
集合属性({
值:val
});
};
const updateSecondValue=(val)=>{
集合属性({
引文:瓦尔
});
};
返回(
);
};
unregisteredBlock.save=({attributes,className})=>{
返回(
{attributes.value}

{attributes.引文} ) }; wp.blocks.registerBlockType('core/quote',unregisteredBlock); });
原则上,编辑和保存方法在这里都被替换,只有块属性从核心块中重用。由于使用新元素输入内容,工具栏不再是问题所在

我希望这能帮助有同样问题的人

干杯, 帕特里克