块编辑器开发文档

💡 云策文档标注

概述

本文档列出了不同 API 版本之间的变更,主要涉及 WordPress 块编辑器(Gutenberg)的 API 版本演进及其对块开发的影响,包括 iframe 渲染和钩子使用等关键更新。

关键要点

  • 版本 3(WordPress 6.3 及以上):当所有注册块支持 Block API 版本 3 或更高时,文章编辑器将使用 iframe 渲染;WordPress 7.0 计划强制所有编辑器在 iframe 中运行。
  • 版本 2(WordPress 5.6 及以上):块作者必须使用 useBlockProps() 钩子来渲染块编辑器的包装元素;静态块的保存标记中不再自动添加类名和样式,需显式使用 useBlockProps.save()。
  • 版本 1:初始版本,无具体变更说明。

注意事项

建议块作者参考迁移指南提前在 iframe 编辑器中测试块兼容性,以确保平滑过渡到新版本。


📄 原文内容

This document lists the changes made between the different API versions.

Version 3 (>= WordPress 6.3)

  • The post editor will be iframed if all registered blocks have a Block API version 3 or higher. Adding version 3 support means that the block should work inside an iframe, though the block may still be rendered outside the iframe if not all blocks support version 3.
  • In WordPress 7.0, the post editor is planned to always work as an iframe, regardless of the apiVersion of registered blocks.
    Please refer to this migration guide to test your blocks in the iframe editor beforehand.

Version 2 (>= WordPress 5.6)

  • To render the block element wrapper for the block’s edit implementation, the block author must use the useBlockProps() hook.
  • The generated class names and styles are no longer added automatically to the saved markup for static blocks when save is processed. To include them, the block author must explicitly use useBlockProps.save() and add to their block wrapper.

Version 1

Initial version.