插件开发文档

插件开发入门

💡 云策文档标注

概述

本文档是 WordPress 插件开发手册的入门部分,旨在帮助开发者编写高质量的插件,无论经验水平如何。它强调了避免修改 WordPress 核心的重要性,并介绍了插件的基本结构和作用。

关键要点

  • 插件开发的核心原则是“不要修改 WordPress 核心”,因为核心文件会在更新时被覆盖,所有功能扩展都应通过插件实现。
  • 插件可以非常简单(如单个 PHP 文件)或复杂,取决于需求,例如 Hello Dolly 插件展示了基本结构。
  • 插件通过 Plugin Header、PHP 函数和 hooks 来扩展 WordPress 功能,手册涵盖从头部信息到安全实践等主题。

📄 原文内容

Welcome to the Plugin Developer Handbook. Whether you’re writing your first plugin or your fiftieth, we hope this resource helps you write the best plugin possible.

The Plugin Developer Handbook covers a variety of topics — everything from what should be in the plugin header, to security best practices, to tools you can use to build your plugin. It’s also a work in progress — if you find something missing or incomplete, please notify the documentation team in slack and we’ll make it better together.

Why We Make Plugins

If there’s one cardinal rule in WordPress development, it’s this: Don’t touch WordPress core. This means that you don’t edit core WordPress files to add functionality to your site. This is because WordPress overwrites core files with each update. Any functionality you want to add or modify should be done using plugins.

WordPress plugins can be as simple or as complicated as you need them to be, depending on what you want to do. The simplest plugin is a single PHP file. The Hello Dolly plugin is an example of such a plugin. The plugin PHP file just needs a Plugin Header, a couple of PHP functions, and some hooks to attach your functions to.

Plugins allow you to greatly extend the functionality of WordPress without touching WordPress core itself.