Created
June 21, 2016 01:42
-
-
Save Nia-TN1012/742705554e3d7c0f666c9e15abfbcec0 to your computer and use it in GitHub Desktop.
PHPの勉強ではじめて作成したWordPress用プラグインです(phpinfo()を実行してPHP情報を表示します)
This file contains hidden or 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: PHP Info. Preview | |
Plugin URI: | |
Description: PHPの情報(phpinfo())を表示するプラグイン | |
Author: Nia Tomonaka | |
Version: 0.1 | |
Author URI: https://chronoir.net/ | |
License: GPL2 | |
*/ | |
// クラス | |
class PHPInfoPrev { | |
// __construct()関数はPHPにおけるクラスのコンストラクターの役割を持ちます。 | |
public function __construct() { | |
// add_action() : WordPressで実行するシステム関数に、指定した関数をフックします。 | |
add_action( | |
// $tag : WordPressのシステム関数(admin_menuはWordPressの管理者画面のメニューです。) | |
'admin_menu', | |
// $function_to_add : フックする関数(※クラスの場合、$this及びフックするメンバー関数を格納した配列を指定します) | |
// ※フックする関数のアクセス権はpubicにする必要があります。 | |
array( $this, 'add_phpinfo_page' ) | |
); | |
} | |
// PHP情報のページを追加します。 | |
public function add_phpinfo_page() { | |
// add_menu_page() : メニュー内の指定した位置にプラグイン用のページを追加します。 | |
add_menu_page( | |
// $page_title : メニューページのタイトル(HTMLのタイトルタグとして表示されます) | |
'PHP Info.', | |
// $menu_title : メニュー名(WordPressの管理者画面のメニュー名として表示されます) | |
'PHP Info.', | |
// $capability : 権限(manage_optionsはオプション設定を行うための権限です) | |
'manage_options', | |
// $menu_slug : メニューのスラッグ(一意的な名前を指定します。「__FILE__」を指定した場合、) | |
__FILE__, | |
// $function : メニューページを表示する時に実行する関数 | |
// ※指定する関数のアクセス権はpubicにする必要があります。 | |
array( $this, 'show_phpinfo' ) | |
); | |
} | |
// phpinfo()を実行し、PHPの情報を管理画面に表示します。 | |
public function show_phpinfo() { | |
phpinfo(); | |
} | |
} | |
// PHPInfoPrevクラスのインスタンスを生成します。 | |
$cn_phpinfo_prev = new PHPInfoPrev; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment