Created
February 4, 2014 15:49
-
-
Save snoise/8806232 to your computer and use it in GitHub Desktop.
管理メニュー・サブメニューありのテキストを末尾に追加するプラグインwordpressプラグイン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: paka3 AddText | |
Plugin URI: http://www.paka3.com/wpplugin | |
Description: テキストを末尾に追加するプラグイン | |
Author: Shoji ENDO | |
Version: 0.1 | |
Author URI:http://www.paka3.com/ | |
*/ | |
//オブジェクトを生成 | |
$addText= new Paka3AddText; | |
//クラス定義 | |
class Paka3AddText { | |
//コンストラクタ | |
function __construct() { | |
add_action('admin_menu', array($this, 'adminAddMenu')); | |
add_filter('the_content',array($this, 'paka3_addtext')); | |
} | |
//管理メニューの設定 | |
function adminAddMenu() { | |
add_menu_page('テキスト追加ページだよ','テキスト追加', 'level_8', __FILE__, array($this,'addIndexText_option_page'), 'dashicons-smiley', 6); | |
add_submenu_page(__FILE__, 'テキスト追加ページだよ', '説明します!', 'level_8', __FILE__, array($this,'addIndexText_option_page')); | |
add_submenu_page(__FILE__, 'テキスト追加ページだよ', 'テキスト入力', 'edit_themes', 'mytheme_setting', array($this,'addText_option_page')); | |
} | |
//表示する内容と処理 | |
function addText_option_page() { | |
//**管理画面「テキスト追加」ページに表示する内容 | |
//1.入力値"paka3_add_text"があった場合の処理 | |
if(isset($_POST['paka3_options']) && check_admin_referer('paka3addtext')){ | |
//更新処理処理 | |
$opt = $_POST['paka3_options']; | |
update_option('paka3_options', $opt); | |
//更新メッセージ | |
echo '<div class="updated fade"><p><strong>'; | |
_e('Options saved.'); | |
echo "</strong></p></div>"; | |
} | |
//2.値の設定 | |
$opt = get_option('paka3_options'); | |
$add_text = isset($opt['text']) ? $opt['text']: null; | |
//3.表示する内容(HTML) | |
$wp_n = wp_nonce_field('paka3addtext'); | |
echo <<<EOS | |
<div class="wrap"> | |
<h2>記事の末尾にテキストを追加</h2> | |
<form method="post" action=""> | |
{$wp_n} | |
<table class="form-table"> | |
<tr valign="top"> | |
<th scope="row"><label for="add_text">追加するテキスト</label></th> | |
<td><input name="paka3_options[text]" type="text" id="add_text" value="$add_text" class="regular-text" /></td> | |
</tr> | |
</table> | |
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存" /></p> | |
</form> | |
</div> | |
EOS; | |
} | |
//表示する内容と処理 | |
function addIndexText_option_page() { | |
//**管理画面「テキスト追加」ページに表示する内容 | |
echo <<<EOS | |
<div class="wrap"> | |
<h2>「テキスト追加」インデックスページ</h2> | |
入力した文字列を末尾に追加するよー。<br /> | |
「テキスト入力」をクリックしてね | |
</div> | |
EOS; | |
} | |
//入力した文字列を呼び出す関数 | |
function get_text(){ | |
$opt = get_option('paka3_options'); | |
return isset($opt['text']) ? $opt['text']: null; | |
} | |
//記事の末尾に文字列を追加する | |
function paka3_addtext($contentData) { | |
if(is_single()){ | |
return $contentData."<h3>".esc_html($this->get_text())."</h3>"; | |
} | |
return $contentData; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment