[WP-Plugins]wp-IniFileLoad 1.x

2008.04.11


[ English ][ Japanese ]

 wp-IniFileLoad is a simple plug-in.
 This plug in offers functions to load necessary common data from IniFile in your WordPress.
 The result is returned an associative array for.

Installation

  1. Download wp-IniFileLoad-1.1.1.zip
  2. Unpack/upload the "wp-IniFileLoad.php" into "wp-content/plugins/".
  3. Activate the plugin from the Admin interface; "Plugins".
  4. Upload your IniFile in your theme or "wp-content/themes/common/".
  5. You load it as arrangement data in function "wp_load_inifile(the-inifile-name)".

Using
 When you need you the data in inifile, it is Function "wp_load_inifile".

  1. The structure of the ini file is the same as the php.ini's.
  2. The result is returned an associative array for.(eg. sample01.ini)
  3. Section "data" and "function" are defined as a special section.(eg. sample03.ini)
  4. Section "data" is put in a "data" key.(eg. sample01.ini)
  5. You can put a space between two names in a section name (exclude "function"). When you wrote the section name, it is parsed to a double associative arrays. (eg. sample02.ini)
  6. When there is a "function" section, with a lambda function defined with a value, the result is converted.(eg. sample03.ini)
  7. The section except "data" and "function" is put in an "option" key.(eg. sample01.ini)


Example

  1. < ?php
  2.   $sample01 = wp_load_inifile('sample01.ini');
  3. ?>

History

ver. 1.0
2008.02.23
first version.
ver. 1.1
2008.03.12
INI data came to have cache.
And I added function wp_clear_inidata and wp_reload_inifile.
ver. 1.1.1
2008.04.11
I did not limit a double associative array to a “data” section.


ここから日本語
 wp-IniFileLoadプラグインは単純なプラグインです。
 このプラグインは、あなたのWordPress上で共通して利用したいデータをINIファイルから読み込むものです。
 結果は連想配列となります。

インストール

  1. wp-IniFileLoad-1.1.1.zip をダウンロードします。
  2. 解凍した「wp-IniFileLoad.php」を 「wp-content/plugins/」に入れます。
  3. 管理画面の「プラグイン」にて、このプラグインを有効にします。
  4. あなたが利用中のテーマか「wp-content/themes/common/」にINIファイルを入れます。
  5. 関数「wp_load_inifile(INIファイル名)」を使って連想配列として読み込みます

使い方
 あなたがINIファイルのデータを必要としたとき、関数「wp_load_inifile」を使用してください

  1. INIファイルの構造は、php.ini の構造と同じです。
  2. 結果は連想配列となります。(sample01.ini 参照)
  3. 「data」セクションと「function」セクションは特別なセクションとして定義しています。(sample03.ini 参照)
  4. 「data」セクションの内容は「data」キー以下に入ります。(sample01.ini 参照)
  5. セクション名("function"以外)に、スペース区切りで二重の名前を付けることができます。 そのセクション名を書いたとき、二重の連想配列に解析されます。(sample02.ini 参照)
  6. 「function」セクションがあるとき, ラムダ関数としてデータを変換処理します。(sample03.ini 参照)
  7. 「data」セクションと「function」セクション以外は「option」キー以下に入れいます。(sample01.ini 参照)

 使用例は上記 Example を見てください。

履歴

ver. 1.0
2008.02.23
最初のバージョン
ver. 1.1
2008.03.12
INIデータをキャッシュするようにした。
それに合わせて、関数 wp_clear_inidata、wp_reload_inifile を追加した。
ver. 1.1.1
2008.04.11
二重の連想配列を「data」セクションに限らないようにした。

作った理由

 なぜ、このプラグインを作ったのか? その理由は、「よく使うデータをどのように登録するか」と悩んだ末のことです。
 1,2回程度 利用するデータならPost Metaでもかまいません。
 しかし、何度も再利用するデータ(たとえば「祝祭日」など)を残しておく方法がなかなか見つかりませんでした。
 最初は$wpdb->optionsに入れました。呼び出しは「get_option」を利用すればよいのですが、ではどうやって値を入れるかが問題です。
 そのためのダミーページを作って、update_optionをするか、データベースに直接UPDATE文を行うか…しかし、それらの方法は使い方としてはトリッキーな方法です。しかもある程度WordPressやデータベースに長けていないと使えません。
 そこで、昔からよくつかわれる共通データの使い方「テキストファイルで保管する」
 しかもWordPressはPHPで作られています。PHPには設定ファイル「php.ini」を使うための関数が用意されています。
 それを利用することにしました。
 これならば、INIファイルを読み込む関数を用意すれば問題解決。
 INIファイルは別途作ってFTPしてもいいですし、管理画面から[管理]-[ファイル]でも修正がききます。
ってね。

メモ

 実は「COMMON_TEMPLATEPATH」という定数を定義しています。
中身は「wp-content/themes/common」です。
なぜこんな定数を用意したか…それについてはまた別の機会に

Entry Filed under: WordPress, プラグイン, プロダクト, 技術情報

No Comments yet Add your own

  • 1. Tomas Kapler  |  4月 11th, 2008 at 11:48 PM

    can you give some example of the ini file? I do not much understand this page :-/

  • 2. BeLive 管理人  |  4月 12th, 2008 at 12:49 AM

    > Mr. Tomas Kapler

    Sorry!!
    I forgot to include a sample file.
    I include a sample in the file which I can download from this page.
    I want you to use it if possible.

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

2010年3月
« 9月    
1234567
891011121314
15161718192021
22232425262728
293031  

BeLive

Tel: 03-5201-3974
Fax: 03-5201-3712
E-mail: request@belive.jp
more...

Sales

レンタルサーバ CPI
レンタルサーバ X-bit
会計ソフトのピクシス
2万人のSOHOプロフィールを掲載中!!!
【@SOHO】
SOHO,在宅ワークの求人
いべんとするなら、いべんとじょぶ!
いべんとじょぶ!

Most Recent Posts

Posts by Month

Feeds