块编辑器开发文档

小部件块编辑器概述

💡 云策文档标注

概述

小部件块编辑器是 WordPress 的一项新功能,它将小部件区域升级为允许同时使用块和小部件,提供基于熟悉的块编辑器构建的新管理体验。

关键要点

  • 可通过外观 → 小部件或外观 → 自定义 → 小部件访问编辑器,支持在独立编辑器或自定义器中操作。
  • 在自定义器中使用时,提供实时预览、计划更改等特定功能,增强编辑体验。
  • 旧有小部件通过 Legacy Widget 块保持兼容,第三方插件注册的小部件也可通过此块插入。
  • 编辑器使用底层“Block”小部件存储数据,确保插件和主题正常运作,且可禁用而无数据丢失。
  • 主题可通过 remove_theme_support( 'widgets-block-editor' ) 禁用编辑器,用户可安装 Classic Widgets 插件禁用。

📄 原文内容

Widgets Block Editor

The new Widgets Editor is a WordPress feature which upgrades widget areas to allow using blocks alongside widgets. It offers a new widget management experience built using the familiar WordPress block editor.

You can access the new Widgets Editor by navigating to Appearance Widgets or Appearance Customize Widgets and choose a widget area.

The Widgets Block Editor allows you to insert blocks and widgets into any of the Widget Areas or Sidebars defined by the site’s active theme, via a standalone editor or through the Customizer.

Customizer Widgets Block Editor

The new Widgets Editor also replaces the Widgets section in the Customizer with the new block-based editor.

You can access the Customizer Widgets Block Editor by navigating to Appearance Customize, selecting Widgets, and then selecting a Widget Area.

Using the new Widgets Editor through the Customizer goes beyond inserting blocks and widgets into a selected Widget Area, making use of the live preview of the changes, to the right of the editor, and of all the other Customizer specific features such as scheduling and sharing changes.

Compatibility

Widgets that were added to a Widget Area before the new Widgets Editor will continue to work – via the Legacy Widget block.

The Legacy Widget block is the compatibility mechanism which allows us to edit and preview changes to a classic widget within the new block based Widgets Editor.

Any third party widgets registered by plugins can still be inserted in widget areas by adding and setting them up through a Legacy Widget block.

The Widgets Editor stores blocks using an underlying “Block” widget that is invisible to the user. This means that plugins and themes will continue to work normally, and that the Widgets Block Editor can be disabled without any data loss.

Themes may disable the Widgets Block Editor using remove_theme_support( 'widgets-block-editor' ).

Users may disable the Widgets Block Editor by installing the Classic Widgets plugin.