首页 > 解决方案 > editor.BlockListBlock 过滤器未将 BlockListBlock 传递给 Function

问题描述

当我有define( 'SCRIPT_DEBUG', true );In mywp-config.php时,我通过调用这个钩子接收到正确的对象:editor.BlockListBlock。当我有define( 'SCRIPT_DEBUG', false );或没有定义时,我收到了错误的对象。

const { createHigherOrderComponent } = wp.compose;

const withClientIdClassName = createHigherOrderComponent( ( BlockListBlock ) => {
// BlockListBlock returns as "WithSelect" with debug off
// and returns as the correct component with debug on
    console.log(BlockListBlock);
    return ( props ) => {
    const {attributes, name} = props;
        if(name === 'project/block-name'){
            return <BlockListBlock { ...props } className={'classes-i-want-on-this'} />;
        } else {
            return <BlockListBlock { ...props } />;
        }

    };
}, 'withClientIdClassName' );

wp.hooks.addFilter( 'editor.BlockListBlock', 'classNames-for-cells', withClientIdClassName );

未定义 SCRIPT_DEBUG 或为 false

在此处输入图像描述

使用 SCRIPT_DEBUG 为真

在此处输入图像描述

我用它来启动我的项目 https://github.com/ahmadawais/create-guten-block

标签: wordpressreactjswordpress-gutenberggutenberg-blockscreate-guten-block

解决方案


推荐阅读