解析コード
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
/** * Plugin Name: Responsive Coming Soon * Version: 1.9.2 */ <?php //-------------------------------------------------------- // ■PRO版有効チェック // ◆plugin_dir_path():プラグインのパス名を取得する //-------------------------------------------------------- if (isset($_GET['wpsm_coming_soon_pro_preview']) && ($_GET['wpsm_coming_soon_pro_preview'] == 'true')) { //-------------------------------------------------------- // ▼PRO版が有効な場合 // テンプレート1ルートに遷移する //-------------------------------------------------------- $file = plugin_dir_path(__FILE__)."templates/template1/index.php"; //$file: プラグインのファイル名 include($file); exit(); } //-------------------------------------------------------- // ■リダイレクト機能 // ◆unserialize(): 保存用表現からPHPの値を生成する(シリアル化された変数をPHP変数値に変換する(戻す)) // ◆get_option(): optionsデータベーステーブルから指定した名前のオプション値を取得する // ◆preg_match(): $patternで指定した正規表現により、$subjectを検索する // ◆is_user_logged_in():ログインしているかチェックする // ◆plugin_dir_path(): プラグインのパス名を取得する // ◆current_user_can(): 現在のユーザーが権限を持つ、またはその権限を持つグループに属しているか確認する //-------------------------------------------------------- add_action('template_redirect', //$hook: フックされるアクション名:テーマテンプレートファイルの振り分け直前 'wpsm_coming_soon_redirect'); //$function_to_add: フックする関数名 function wpsm_coming_soon_redirect() { //-------------------------------------------------------- // ▼CSP状態(プラグイン状態?)を取得する //-------------------------------------------------------- $wpsm_rcs_plugin_options_dashboard = unserialize(get_option('wpsm_rcs_plugin_options_dashboard')); //$str: シリアル化された文字列 //$option: 取得するオプション名 $wpsm_csp_status = $wpsm_rcs_plugin_options_dashboard['wpsm_csp_status']; //-------------------------------------------------------- // ▼CSP状態を確認する //-------------------------------------------------------- if($wpsm_csp_status=="1") { //-------------------------------------------------------- // ▼XXXの場合 //-------------------------------------------------------- if(preg_match("/login|admin|dashboard|account/i", //$pattern: 検索パターンを表す文字列 $_SERVER['REQUEST_URI']) > 0) { //$subject: 入力文字列 //-------------------------------------------------------- // ▼カスタムログインページの場合 //-------------------------------------------------------- return false; } //-------------------------------------------------------- // ▼ユーザーログインチェック //-------------------------------------------------------- if (!is_user_logged_in()) { //-------------------------------------------------------- // ▼ログインしていない場合 //-------------------------------------------------------- $file = plugin_dir_path( __FILE__ )."templates/template1/index.php"; //$file: プラグインのファイル名 include($file); exit(); } else { //-------------------------------------------------------- // ▼ログインしている場合 //-------------------------------------------------------- if(false === current_user_can('administrator')) { //-------------------------------------------------------- // ▼管理者ではない場合 //-------------------------------------------------------- $file = plugin_dir_path( __FILE__ )."templates/template1/index.php"; //$file: プラグインのファイル名 include($file); exit(); } } } } //-------------------------------------------------------- // ■管理メニューバー // ◆unserialize():保存用表現からPHPの値を生成する(シリアル化された変数をPHP変数値に変換する(戻す)) // ◆get_option(): optionsデータベーステーブルから指定した名前のオプション値を取得する //-------------------------------------------------------- add_action('admin_bar_menu', //$hook: フックされるアクション名:管理メニューバーロード時 'wpsm_rcs_admin_bar_menu', //$function_to_add: フックする関数名 1000); //$priority: 特定のアクションに関連づけられている関数が実行される優先順序を指定する(小さいほうが早い) function wpsm_rcs_admin_bar_menu() { global $wp_admin_bar; //-------------------------------------------------------- // ▼CSP状態(プラグイン状態?)を取得する //-------------------------------------------------------- $wpsm_rcs_plugin_options_dashboard = unserialize(get_option('wpsm_rcs_plugin_options_dashboard')); //$str: シリアル化された文字列 //$option: 取得するオプション名 $wpsm_csp_status = $wpsm_rcs_plugin_options_dashboard['wpsm_csp_status']; //-------------------------------------------------------- // ▼CSP状態を確認する //-------------------------------------------------------- if($wpsm_csp_status=='0') { return; } //-------------------------------------------------------- // ▼XXX //-------------------------------------------------------- $msg = __('Coming Soon Mode Active', ''); //-------------------------------------------------------- // ▼親メニュー追加 //-------------------------------------------------------- $argsParent = array('id' => 'myCustomMenu', 'title' => $msg, 'parent' => 'top-secondary', 'href' => '?page=wpsm_responsive_coming_soon', 'meta' => array('class' => 'wpsm_cs_active'),); $wp_admin_bar->add_menu($argsParent); ?> <style> .wpsm_cs_active a { background: #31a3dd !important; color: #fff !important; } .wpsm_cs_active a:hover { background: #31a3dd !important; color: #fff !important; } </style> <?php } ?> |
関数リンク
・add_action()・current_user_can()
・get_option()
・is_user_logged_in()
・plugin_dir_path()
・preg_match()
・unserialize()
ベースコード
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
<?php //Live Preview code if ((isset($_GET['wpsm_coming_soon_pro_preview']) && ($_GET['wpsm_coming_soon_pro_preview'] == 'true'))) { $file = plugin_dir_path(__FILE__ )."templates/template1/index.php"; include($file); exit(); } function wpsm_coming_soon_redirect() { $wpsm_rcs_plugin_options_dashboard = unserialize(get_option('wpsm_rcs_plugin_options_dashboard')); $wpsm_csp_status = $wpsm_rcs_plugin_options_dashboard['wpsm_csp_status']; if($wpsm_csp_status=="1") { // Exit if a custom login page if(preg_match("/login|admin|dashboard|account/i", $_SERVER['REQUEST_URI']) > 0) { return false; } // Check if user is logged in. if (!is_user_logged_in()) { $file = plugin_dir_path( __FILE__ )."templates/template1/index.php"; include($file); exit(); } else { if(false === current_user_can('administrator')) { $file = plugin_dir_path( __FILE__ )."templates/template1/index.php"; include($file); exit(); } } } } add_action('template_redirect', 'wpsm_coming_soon_redirect'); add_action('admin_bar_menu', 'wpsm_rcs_admin_bar_menu', 1000); function wpsm_rcs_admin_bar_menu() { global $wp_admin_bar; $wpsm_rcs_plugin_options_dashboard = unserialize(get_option('wpsm_rcs_plugin_options_dashboard')); $wpsm_csp_status = $wpsm_rcs_plugin_options_dashboard['wpsm_csp_status']; if($wpsm_csp_status=='0') { return; } $msg = __('Coming Soon Mode Active', ''); // Add Parent Menu $argsParent=array('id' => 'myCustomMenu', 'title' => $msg, 'parent' => 'top-secondary', 'href' => '?page=wpsm_responsive_coming_soon', 'meta' => array('class' => 'wpsm_cs_active'),); $wp_admin_bar->add_menu($argsParent); ?> <style> .wpsm_cs_active a { background: #31a3dd !important; color: #fff !important; } .wpsm_cs_active a:hover { background: #31a3dd !important; color: #fff !important; } </style> <?php } ?> |