当サイト、Codex 日本語版は今後積極的な更新は行わない予定です。後継となる新ユーザーマニュアルは、https://ja.wordpress.org/support/ にあります。
万が一、当サイトで重大な問題を発見した際などは、フォーラムWordSlack #docs チャンネルでお知らせください。</p>

ファイルヘッダー

提供: WordPress Codex 日本語版
2013年5月19日 (日) 23:32時点におけるDjkaz (トーク | 投稿記録)による版 (途中まで訳しました)

移動先: 案内検索

WordPressに於いて、テーマプラグインは一つ以上の(Drop-Ins, Must-Use-Plugins:を持つことがある)、所謂File Headersを持ち、メタ情報(名前、ヴァージョン、作者、等)を含む。

File Headersはファイルの先頭ブロック(必ずしも一番先頭である必要はないが)にあり、一つのヘッダが一行である。ヘッダはNameValueからなる。

File Headerの例

以下の、file header examplesはテーマとプラグインの例から引用されたもので、WordPressと一緒に提供されるまたはWordPressプロジェクトに極めて近く関連しているものである(初期テーマおよびコアとなるプラグインである):

プラグインFile Headerの例

プラグインのヘルスチェックを行うために、health-check.phpファイルの一番最初の行に以下が記載されている:

<?php
/*
	Plugin Name: Health Check
	Plugin URI: http://wordpress.org/extend/plugins/health-check/
	Description: Checks the health of your WordPress install
	Author: The Health Check Team
	Version: 0.1-alpha
	Author URI: http://wordpress.org/extend/plugins/health-check/
	Text Domain: health-check
	Domain Path: /lang
 */

class HealthCheck {
[...]

テーマFile Headerの例

Twentytenテーマの一部である、style.cssファイルの一番最初のラインには以下が記載せれている:

/*
Theme Name: Twenty Ten
Theme URI: http://wordpress.org/
Description: The 2010 theme for WordPress is stylish, customizable, simple, and readable -- make it yours with a custom menu, header image, and background. Twenty Ten supports six widgetized areas (two in the sidebar, four in the footer) and featured images (thumbnails for gallery posts and custom header images for posts and pages). It includes stylesheets for print and the admin Visual Editor, special styles for posts in the "Asides" and "Gallery" categories, and has an optional one-column page template that removes the sidebar.
Author: the WordPress team
Version: 1.2
License: GNU General Public License
License URI: license.txt
Tags: black, blue, white, two-columns, fixed-width, custom-header, custom-background, threaded-comments, sticky-post, translation-ready, microformats, rtl-language-support, editor-style, custom-menu
*/

ヘッダー名のリスト

以下が、2010年6月2日現在のテーマとプラグインにデフォルトで実装されいているFile Headerのヘッダー名リストである。ヘッダーは拡張可能なためこれはサブセットであり、上位セットではない:

プラグイン

  • Author (Plugin)
  • Author URI (Plugin)
  • Description (Plugin)
  • Domain Path (Plugin)
  • Network (Plugin)
  • Plugin Name (Plugin)
  • Plugin URI (Plugin)
  • Site Wide Only (Plugin; deprecated in favor of Network)
  • Text Domain (Plugin)
  • Version (Plugin)

テーマ

  • Author (Theme)
  • Author URI (Theme)
  • Description (Theme)
  • Status (Theme)
  • Tags (Theme)
  • Template (Theme)
  • Theme Name (Theme)
  • Theme URI (Theme)
  • Version (Theme)

ページテンプレート

いくつかのプラグインヘッダーの説明については、プラグイン File Headersを、テーマヘッダーについてはテーマスタイルシートを、それぞれ参照してください。

If you are unable to find a concrete specification for the one or other header, you need to read the WordPress source-code to find out more specific information about them (please see File Header Related Functions below for a list of related functions and hooks).

File Header Filenames

Since multiple files in a plugin/theme can contain meta information, the following are the file-names and the order (from top to bottom) of which files are parsed for headers.

Plugin

  1. Each PHP-file in the directory order. If a file does not contain the Name header, it won't be treated as a plugin.

Theme

  1. The style.css CSS-file

Must-Use Plugin

  1. The concrete PHP-file

Drop-In

  1. The concrete PHP-file

File Header Specification

Per de-facto implementation, File Headers can be specified as the following:

  1. Header are written in a block in the beginning of a PHP or CSS file.
  2. A block might be placed in a files comment, like a PHP or CSS comment.
  3. The whole header block must be placed inside the first 8 192 bytes of the file.
  4. Headers follow up to each other, one on it's own line.
  5. A header consists of a name and a value.
  6. Name and value are separated by the ':' character.
  7. The name has a minimum of one, and a maximum of three words.
  8. The minimum length of a word is three, the maximum length is 12 characters.
  9. A word consists of the characters a-z and A-Z.
  10. Words are separated by a single space (d32/x20)
  11. A name starts after the beginning of a line or after a whitespace character.
  12. A name ends before the ':' character.
  13. A value starts after the ':' character.
  14. Sometimes the ':' character is suffixed by a space. This space is considered to not be part of the value.
  15. A header-value can contain any characters but not a newline.
  16. Header values might become filtered before they are used.
  17. Header values can but must not contain HTML code in form of certain XHTML Elements or HTML Tags.

Note: Because of the nature that there are individual headers, the maximum number of words as well as the minimum and maximum number of characters per word are based on default headers. Because this is a subset and not the superset of all header names, this might vary depending on the implementation and plugins you are using.

File Header Related Functions

The File Header API consists of all functions regarding theme and plugin file headers and related hooks (actions, filters).

Header Context

Some of the API functions provide the possibility to add a context to headers. There are two contexts defined in the wordpress core code: Themes ('theme') and Plugins ('plugin').

File Headers in readme.txt

Some plugins contain the readme.txt file which might contain look-a-like headers as well. Those files are not handled by WordPress but by third-party applications. Because those applications can be quite popular, I note down here those tags from an example readme file:

Contributors: markjaquith, mdawaffe (this should be a list of wordpress.org userid's)
Donate link: http://example.com/
Tags: comments, spam
Requires at least: 2.0.2
Tested up to: 2.1
Stable tag: 4.3

As ticket #12260 suggests, the headers from readme.txt are used through remote WP.org API calls. This is a good example of how third party applications use has direct impact on wordpress core code usage.