(以下、機能文字は全角で記載してあるので、半角に読みかえること。)
1.(site)\wp-content\plugins\ の下にフォルダーを作る。プラグイン名と同じがよい。
2.そこに「プラグイン名.php」をつくる。 例 : my_plugin_1.php
3.内容はこんな感じ :
<?php
/**
Plugin Name: my plugin 1
Plugin URI:
Description: my test plugin no_1.
Author: Author Name
Author URI:
Text Domain:
Domain Path:
Version: 0.0.0
*/
add_shortcode("show_my_plugin_1", "my_plugin_1_page");
function my_plugin_1_page() {
return ’<p>何かのコンテンツ</p>’;
}
4.ダッシュボードのプラグイン一覧を開くと、「my plugin 1」が載っているので、有効化する。表示されている名称はコード冒頭の「Plugin Name」で指定したもの。5.投稿中に [show_my_plugin_1] と書くと、「何かのコンテンツ」が表示される。
これをクラスにするにはこんな感じ :
class myPlugin1Class {
public function __construct() {
//コンストラクタで add_shortcode する。
//以下の、配列にして $this を渡すことがミソ。
add_shortcode("show_my_plugin_1", array($this, "my_plugin_1_page"));
}
public function my_plugin_1_page() {
return ’<p>何かのコンテンツ</p>’;
}
//インスタンスを生成; 変数への保存は不要
new myPlugin1Class();
6.例によって、「ミソ」を発見するのに一苦労あったので、メモ。
0 件のコメント:
コメントを投稿