官术网_书友最值得收藏!

Information header

Don't just skim this section thinking it's a waste of breath on the self-explanatory header fields. Unlike a normal PHP file in which the comments are purely optional, in WordPress plugin and theme files, the Information Header is required! It is this block of text that causes a file to show up on WordPress' radar so that you can activate it or deactivate it. If your plugin is missing a valid information header, you cannot use it!

Exercise—breaking the header

To reinforce that the information header is an integral part of a plugin, try the following exercise:

  1. In your WordPress Dashboard, ensure that the "Hello Dolly" plugin has been activated.
  2. If applicable, use your preferred (s)FTP program to connect to your WordPress installation.
  3. Using your text editor, temporarily delete the information header from wp-content/plugins/hello.php and save the file (you can save the header elsewhere for now). Save the file.
  4. Refresh the Plugins page in your browser.
  5. You should get a warning from WordPress stating that the plugin does not have a valid header:

After you've seen the tragic consequences, put the header information back into the hello.php file.

This should make it abundantly clear to you that the information header is absolutely vital for every WordPress plugin. If your plugin has multiple files, the header should be inside the primary file—in this book we use index.php as our primary file, but many plugins use a file named after the plugin name as their primary file.

Location, name, and format

The header itself is similar in form and function to other content management systems, such as Drupal's module.info files or Joomla's XML module configurations—it offers a way to store additional information about a plugin in a standardized format. The values can be extended, but the most common header values are listed below:

  • Author: Listed below the plugin name
  • Author URI: Together with "Author", this creates a link to the author's site
  • Description: Main block of text describing the plugin
  • Plugin Name: The displayed name of the plugin
  • Plugin URI: Destination of the "Visit plugin site" link
  • Version: Use this to track your changes over time

For more information about header blocks, see the WordPress codex at: http://codex.wordpress.org/File_Header.

Tip

In order for a PHP file to show up in WordPress' Plugins menu:

  • The file must have a .php extension.
  • The file must contain the information header somewhere in it (preferably at the beginning).
  • The file must be either in the /wp-content/plugins directory, or in a subdirectory of the plugins directory. It cannot be more deeply nested.
主站蜘蛛池模板: 汉中市| 长葛市| 普安县| 岐山县| 厦门市| 南汇区| 绥中县| 灵寿县| 伽师县| 富顺县| 宝应县| 汤阴县| 开原市| 贵南县| 万宁市| 宁化县| 皋兰县| 大埔县| 河北省| 新乡县| 盐津县| 滦南县| 明溪县| 沁阳市| 皋兰县| 台北市| 曲水县| 嫩江县| 嘉鱼县| 武定县| 五台县| 汝阳县| 巩义市| 益阳市| 彭州市| 吴川市| 陆河县| 平邑县| 濮阳市| 青州市| 鸡东县|