页头要求

入门中所述,主PHP文件应该包含页头注释,它告诉WordPress该文件是一个插件,并提供关于插件的信息。

最少字段

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

/**
 * Plugin Name: YOUR PLUGIN NAME
 */

 

页头字段

可用的页头字段:

  • Plugin Name:必需)插件的名称,将显示在WordPress后台管理的插件列表中。
  • Plugin URI: 插件的主页,它应该是一个唯一的URL,最好在您自己的网站上。这个对于插件来说必须是唯一的。您不能在此处使用WordPress.org URL。
  • Description: 插件的简短描述,如WordPress后台管理中的插件所示,将此描述保持在140个字符以下。
  • Version: 插件的当前版本号,如1.0或1.0.3。
  • Requires at least: 插件将使用的最低WordPress版本。
  • Requires PHP: 所需的最低PHP版本。
  • Author: 插件作者的名称。可以使用逗号列出多个作者。
  • Author URI: 作者的网站或其他网址,如WordPress.org上的个人资料页面。
  • License: 插件许可证(例如GPLv2)的短名称(slug)。有关许可的更多信息可以在WordPress.org指南中找到。
  • License URI: 指向许可证全文的链接(例如https://www.gnu.org/licenses/gpl-2.0.html)。
  • Text Domain: 插件的gettext文本域。更多信息可以在如何国际化插件页面的文本域部分找到。
  • Domain Path: 域路径让WordPress知道在哪里可以找到翻译。更多信息可以在如何国际化插件页面的域路径部分找到。
  • Network: 插件是否只能在网络范围内激活。只能设置为true,不需要时应忽略。
  • Update URI: 允许第三方插件避免意外地被WordPress.org插件目录中类似名称的插件的更新所覆盖。有关更多信息,请阅读相关的开发说明

带有页头注释的有效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
 */

下面是另一个允许文件级PHPDoc DocBlock和WordPress插件文件头的示例:

/**
 * 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/
 */

 

注意

Alert:为项目分配版本号时,请记住WordPress使用PHPversion_compare()函数来比较插件版本号。因此,在发布插件的新版本之前,应该确保这个PHP函数认为新版本比旧版本号“更大”。例如,1.02实际上比1.1要大。