Home > plugin

plugin

  • 2008-03-08 (土) 8:59

pluginを自作メモ

source

※wordpressMUのプラグインは、サイト管理オプションで利用するにチェックを入れないと、メニューに表示しません。

<?php
/*
Plugin Name: convert smilePlugin
URI: http://text2html.s321.xrea.com/
Description: :)をスマイル画像に変換
Version: 1Author: s321
Author URI: http://text2html.s321.xrea.com/
*/
/*
*hook に関数を追加
*-----------*/
add_filter('the_content', 'smile');
/*
*関数を定義
*-----------*/
function smile($content) {
$smile = "<img src="/images/hoge.jpg" />";

$smile = str_replace(':)',$smile,$content);
return $smile;
}
?>

WordPress(以下WP)Pluginとは、

WPの機能をカスタマイズするために、外部のphp関数を利用できるようにする仕組みがある。

例えば、新しい投稿を行ったときに、友人にメールを送信するといった作業を自動的に行ってくれるプログラムを記述しておいて、自動的に実行させるといった機能をさす。

プログラムは、特別な制約を含むものではないので、ブログの効率的な運営の役に立つこともあれば、深刻な影響を与えることもある。

DataBaseへのアクセスを伴うプラグインは、データの改ざん、削除、 等と直接結びつく作業なので、特に注意を要する。

使い方

pluginは、wp-content/plugin/にファイルまたは、ディレクトリを作り、配置、有効に設定することで利用できるようになる。

作り方:

  • phpで記述する
  • 制作者情報等を入力する必要がある。この情報は、ブログのプラグインリストに表示される。 /*
    Plugin Name: first_plugin
    Plugin URI: http://text2html.s321.xrea.com/plugin/
    Description: 初めてのプラグイン
    Version: 1
    Author: tenman
    Author URI: http://text2html.s321.xrea.com/
    */
  • イベントリスナーとか、イベントプロシージャといったイベントに呼応する仕組みのことを、wordpressでは、hookという。 wordpressの、add_action、add_filterを使って、関数を実行する。
  • actionまたはfilterの追加
  • add_action(フック, アクション, プライオリティ {オプション})
    add_filter(フック, アクション, プライオリティ {オプション})
  • actionまたはfilterの削除
  • remove_filter(’filter_hook’,'filter_function’)
    remove_action(’action_hook’,'action_function’)
  • 作業の流れ
    1. phpで関数をつくります。引数は1個
    2. add_action を作る。どんなイベントのときに使うか良く考えて、
    3. プラグインをアクティベートして使う。

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://text2html.s321.xrea.com/wp/wordpress/plugin/trackback/
Listed below are links to weblogs that reference
plugin from wordpress note

Home > plugin

Search
Feeds
Meta

Return to page top