【问题标题】:WP Gutenberg, remove core panel options?WP Gutenberg,删除核心面板选项?
【发布时间】:2021-04-09 06:14:10
【问题描述】:

有谁知道是否可以从古腾堡的核心块中删除一些默认面板?

我正在特别考虑调色板面板(仅在某些块上,例如我不希望用户能够更改按钮上的颜色)。或按钮边框半径...与核心/覆盖高度相同。

我已经尝试了几乎所有我能想到的东西,并且想知道我是否必须为这些小改动创建自己的自定义块。

【问题讨论】:

标签: wordpress-gutenberg gutenberg-blocks


【解决方案1】:

我尝试尝试更改块 settings.supports 对象,运气不错...我说一些是因为我无法完全删除我想要的所有面板,但确实设法删除了像这样的颜色和排版面板之类的东西.

参考链接

import assign from "lodash.assign";
import { addFilter } from "@wordpress/hooks";

const extendOnBlocks = ["core/button"]; // replace with ["core/cover"]

const removeBlockPanels = (settings, name) => {
  // Do nothing if it's another block than our defined ones.
  if (!extendOnBlocks.includes(name)) {
    return settings;
  }

  // Use Lodash's assign to gracefully handle if attributes are undefined
  settings.supports = assign(settings.supports, {
    __experimentalBorder: false,
    typography: false,
    color: false,
  });

  return settings;
};
addFilter(
  "blocks.registerBlockType",
  "my-button/attribute/options",
  removeBlockPanels
);

【讨论】:

    猜你喜欢
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-20
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    相关资源
    最近更新 更多