WordPress 插件开发手册

title: "头部要求" post_status: publish comment_status: open taxonomy: category: - developer-plugins-handbook post_tag: - Header Requirements - Plugin Basics - Repos


头部要求

入门指南所述,主 PHP 文件应包含头部注释,以告知 WordPress 该文件是一个插件并提供插件相关信息。

最低要求字段

至少,头部注释必须包含插件名称:

/*
 * Plugin Name: 你的插件名称
 */

头部字段

可用的头部字段:

一个包含头部注释的有效 PHP 文件可能如下所示:

/*
 * Plugin Name:       My Basics Plugin
 * Plugin URI:        https://example.com/plugins/the-basics/
 * Description:       Handle the basics with this plugin.
 * Version:           1.10.3
 * Requires at least: 5.2
 * Requires PHP:      7.2
 * Author:            John Smith
 * Author URI:        https://author.example.com/
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       my-basics-plugin
 * Domain Path:       /languages
 */

Here's another example which allows file-level PHPDoc DocBlock as well as WordPress plugin file headers:

/**
 * Plugin Name
 *
 * @package           PluginPackage
 * @author            Your Name
 * @copyright         2019 Your Name or Company Name
 * @license           GPL-2.0-or-later
 *
 * @wordpress-plugin
 * Plugin Name:       Plugin Name
 * Plugin URI:        https://example.com/plugin-name
 * Description:       Description of the plugin.
 * Version:           1.0.0
 * Requires at least: 5.2
 * Requires PHP:      7.2
 * Author:            Your Name
 * Author URI:        https://example.com
 * Text Domain:       plugin-slug
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.txt
 */

注意事项

[alert]为项目分配版本号时,请注意 WordPress 使用 PHP version_compare() 函数来比较插件版本号。因此,在发布插件新版本前,应确保此 PHP 函数认为新版本"大于"旧版本。例如,1.02 实际上大于 1.1。[/alert]