[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
- Download wp-IniFileLoad-1.1.1.zip
- Unpack/upload the "wp-IniFileLoad.php" into "wp-content/plugins/".
- Activate the plugin from the Admin interface; "Plugins".
- Upload your IniFile in your theme or "wp-content/themes/common/".
- 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".
- The structure of the ini file is the same as the php.ini's.
- The result is returned an associative array for.(eg. sample01.ini)
- Section "data" and "function" are defined as a special section.(eg. sample03.ini)
- Section "data" is put in a "data" key.(eg. sample01.ini)
- 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)
- When there is a "function" section, with a lambda function defined with a value, the result is converted.(eg. sample03.ini)
- The section except "data" and "function" is put in an "option" key.(eg. sample01.ini)
- < ?php
- $sample01 = wp_load_inifile('sample01.ini');
- ?>
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.
ここから日本語
wp-IniFileLoadプラグインは単純なプラグインです。
このプラグインは、あなたのWordPress上で共通して利用したいデータをINIファイルから読み込むものです。
結果は連想配列となります。
インストール
- wp-IniFileLoad-1.1.1.zip をダウンロードします。
- 解凍した「wp-IniFileLoad.php」を 「wp-content/plugins/」に入れます。
- 管理画面の「プラグイン」にて、このプラグインを有効にします。
- あなたが利用中のテーマか「wp-content/themes/common/」にINIファイルを入れます。
- 関数「wp_load_inifile(INIファイル名)」を使って連想配列として読み込みます
使い方
あなたがINIファイルのデータを必要としたとき、関数「wp_load_inifile」を使用してください
- INIファイルの構造は、php.ini の構造と同じです。
- 結果は連想配列となります。(sample01.ini 参照)
- 「data」セクションと「function」セクションは特別なセクションとして定義しています。(sample03.ini 参照)
- 「data」セクションの内容は「data」キー以下に入ります。(sample01.ini 参照)
- セクション名("function"以外)に、スペース区切りで二重の名前を付けることができます。 そのセクション名を書いたとき、二重の連想配列に解析されます。(sample02.ini 参照)
- 「function」セクションがあるとき, ラムダ関数としてデータを変換処理します。(sample03.ini 参照)
- 「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」です。
なぜこんな定数を用意したか…それについてはまた別の機会に


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