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

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.
主站蜘蛛池模板: 柳州市| 安徽省| 进贤县| 盐城市| 泗水县| 方正县| 临汾市| 靖边县| 云阳县| 岱山县| 简阳市| 马鞍山市| 襄垣县| 南平市| 新津县| 甘谷县| 阿瓦提县| 仪征市| 信丰县| 沐川县| 晋城| 肃宁县| 孙吴县| 怀集县| 英吉沙县| 遵义县| 万源市| 江源县| 伊通| 邵阳市| 游戏| 五寨县| 上栗县| 安仁县| 太谷县| 监利县| 汕头市| 伊通| 东方市| 迭部县| 淮北市|