块编辑器开发文档

💡 云策文档标注

概述

钩子是代码间交互或修改的机制,允许插件、主题与编辑器交互,并广泛应用于 WordPress 核心。WordPress 支持 PHP 和 JavaScript 两种钩子类型。

关键要点

  • 钩子分为 Actions 和 Filters 两种类型。
  • 除了 PHP 钩子,WordPress 还提供 JavaScript 钩子机制,可通过 @wordpress/hooks 包在 npm 上使用。
  • 开发者可参考 PHP 和 JavaScript 的 API 文档深入学习钩子功能。

📄 原文内容

Hooks are a way for one piece of code to interact/modify another piece of code. They provide one way for plugins and themes to interact with the editor, but they’re also used extensively by WordPress Core itself.

There are two types of hooks: Actions and Filters. In addition to PHP actions and filters, WordPress also provides a mechanism for registering and executing hooks in JavaScript. This functionality is also available on npm as the @wordpress/hooks package, for general purpose use.

You can also learn more about both APIs: PHP and JavaScript.