限制 WordPress 核心列块中的列数

问题描述 投票:0回答:1

我想在 WordPress Gutenberg 的核心列块中将列数限制为三个。

期望的结果 - WP 管理员在 Gutenberg 中添加列块时不允许来自

RangeController
的三列以上。

enter image description here

如果你有任何想法,非常感谢。

我尝试使用 editor.BlockEdit 钩子来替换现有的 RangeController 但没有成功。 https://developer.wordpress.org/block-editor/reference-guides/filters/block-filters/#editor-blockedit

https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/columns/edit.js

wordpress wordpress-gutenberg
1个回答
0
投票

取消注册块变化可以限制插入列块时可用列选项的数量。

如果你想删除一些 default variations of the column block that are not 3 columns, you can unregister them by name, eg:

wp.blocks.unregisterBlockVariation('core/columns', 'one-column-full');
wp.blocks.unregisterBlockVariation('core/columns', 'two-columns-equal');
wp.blocks.unregisterBlockVariation('core/columns', 'two-columns-one-third-two-thirds');
wp.blocks.unregisterBlockVariation('core/columns', 'two-columns-two-thirds-one-third');

这会将列插入器显示为: 注意。 编辑器仍将允许用户通过

RangeControl
用户界面将列数增加到允许的最大值 6.

如果您想完全删除用户更改 UI 中列数的能力,我建议添加 JavaScript 来设置输入

min|max="3"
和/或通过 CSS 隐藏控件。

© www.soinside.com 2019 - 2024. All rights reserved.