本文档介绍了 WordPress 插件主 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
* Update URI: https://example.com/my-plugin/
* Text Domain: my-basics-plugin
* Domain Path: /languages
* Requires Plugins: my-plugin, yet-another-plugin
*/使用 version_compare() 函数比较版本号时,需注意版本号格式,例如 1.02 大于 1.1。
As described in Getting Started, the main PHP file should include header comment what tells WordPress that a file is a plugin and provides information about the plugin.
At a minimum, a header comment must contain the Plugin Name:
/*
* Plugin Name: YOUR PLUGIN NAME
*/
Available header fields:
my-plugin (my-plugin/my-plugin.php is not supported). It does not support commas in plugin slugs. For more info read the related dev note.A valid PHP file with a header comment might look like this:
/*
* 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
* Update URI: https://example.com/my-plugin/
* Text Domain: my-basics-plugin
* Domain Path: /languages
* Requires Plugins: my-plugin, yet-another-plugin
*/
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: http://www.gnu.org/licenses/gpl-2.0.txt
* Update URI: https://example.com/my-plugin/
* Requires Plugins: my-plugin, yet-another-plugin
*/