前提・実現したいこと
私は現在顧客のHPパッケージの管理業務をしているのですが、
オリジナルで作成したプラグインが正常に動かないため、困っております。
プログラミングの知識は初心者程度でどこが原因がわからずここで質問させていただきます。
プラグインの内容を簡潔に説明すると
wordpressの編集画面で、AUTH設定の画面で各カテゴリーにユーザー名とPW名を設定できるようになり、
カテゴリーをクリックするとID・PWを要求されるようになります。
発生している問題・エラーメッセージ
正しいID・PWを入力しても再度ID・PWを要求させる
該当のソースコード
<?php /* Plugin Name: Categories Basic Authentication Setting Plugin URI: Description: カテゴリ別 Basic認証 Version: 1.0 Author: BCJ Author URI: */ /* ===================================================== WordPressに処理の追加 ===================================================== */ $is_submenu = new IS_Categories_Basic_Auth(); //アクションフックを登録 add_action('admin_menu', array($is_submenu, 'Add_SubMenu')); add_action('init', array($is_submenu, 'Check_Categories_Authentication')); /* ===================================================== クラスの定義 ===================================================== */ class IS_Categories_Basic_Auth { // 設定パネルにメニュー追加 function Add_SubMenu() { // 有効 if( function_exists('add_options_page') ) { // テーマのメニュー追加処理で行うので行わない //- add_options_page('Auth' , 'Auth' , 'edit_themes' , __FILE__ , array($this, 'Authentication_Setting') ); } } // 設定画面の作成 function Authentication_Setting() { $jssrc = WP_PLUGIN_URL . "/categories-basic-authentication/js/jquery.formtips.js"; $my_auth_data = array(); $my_auth_user = ""; $my_auth_pass = ""; if ( array_key_exists('posted' , $_POST) && $_POST['posted'] == 'Y' && array_key_exists('my_auth_data_' , $_POST) ) { foreach ($_POST['my_auth_data_'] as $key => $data) { if( $data[0] && $data[1] && $data[2] ) { $my_auth_data["$key"]['user'] = stripslashes($data[1]); $my_auth_data["$key"]['pass'] = stripslashes($data[2]); } } update_option('my_auth_data', $my_auth_data); } ?> <?php if($_POST['posted'] == 'Y') : ?><div id="message" class="updated"><p>Authを更新しました。<a href="<?php echo home_url( '/' ); ?>">サイト</a>を表示して確認してください。</p></div><?php endif; ?> <script type="text/javascript" src="<?php _e($jssrc); ?>"></script> <script type="text/javascript"> (function($) { $(function() { $('form input.help').formtips({ tippedClass: 'tipped' }); }); })(jQuery); </script> <style type="text/css" media="screen"> .tipped { color: #BBB; } </style> <div class="wrap"> <div id="icon-options-general" class="icon32"><br /></div> <h2>Auth設定</h2> <form method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>"> <input type="hidden" name="posted" value="Y"> <input type="submit" name="Submit" class="button-primary" value="変更を保存" /> <table class="wp-list-table widefat" cellspacing="0"> <thead> <tr> <th scope='col' id='cb' class='manage-column check-column' style=""><!-- input id="region_name_h" type="checkbox" / --></th> <th scope='col' id='name' class='manage-column' style=""><label for="region_name_h"><span>名前</span></label><span class="sorting-indicator"></span></th> <th scope='col' id='slug' class='manage-column' style=""><span>スラッグ</span><span class="sorting-indicator"></span></th> <th scope='col' id='user' class='manage-column' style=""><span>ユーザ名</span><span class="sorting-indicator"></span></th> <th scope='col' id='pass' class='manage-column' style=""><span>パスワード</span><span class="sorting-indicator"></span></th> </tr> </thead> <tfoot> <tr> <th scope='col' id='cb' class='manage-column check-column' style=""><!-- input id="region_name_f" type="checkbox" / --></th> <th scope='col' id='name' class='manage-column' style=""><label for="region_name_f"><span>名前</span></label><span class="sorting-indicator"></span></th> <th scope='col' id='slug' class='manage-column' style=""><span>スラッグ</span><span class="sorting-indicator"></span></th> <th scope='col' id='user' class='manage-column' style=""><span>ユーザ名</span><span class="sorting-indicator"></span></th> <th scope='col' id='pass' class='manage-column' style=""><span>パスワード</span><span class="sorting-indicator"></span></th> </tr> </tfoot> <tbody id="the-list" class='list:tag'> <?php $my_auth_data = array(); $my_auth_data = get_option('my_auth_data'); $cnt = 0; $categories = get_categories(array('parent' => '0')); foreach ($categories as $category) { $my_auth_user = esc_attr($my_auth_data[$category->term_id]['user']); $my_auth_pass = esc_attr($my_auth_data[$category->term_id]['pass']); $checked = ''; if ( $my_auth_data[$category->term_id] ) { $checked = ' checked="checked"'; } ?> <tr id="tag-<?php _e($category->term_id); ?>"<?php if ($cnt % 2 == 0) _e(' class="alternate"'); ?>> <th scope="row" class="check-column"> <input id="my_auth_dirs_<?php _e($category->term_id); ?>" type="checkbox" name="my_auth_data_[<?php _e($category->term_id); ?>][0]" value="YES" <?php _e($checked); ?> /> </th> <td class='name' NOWRAP> <label for="my_auth_dirs_<?php _e($category->term_id); ?>"><strong><?php _e($category->name); ?></strong></label> </td> <td class='slug' NOWRAP> <?php _e($category->slug); ?> </td> <td class='user' NOWRAP> <input class="help" title="半角英数でユーザ名を・・・" name="my_auth_data_[<?php _e($category->term_id); ?>][1]" id="my_auth_user_<?php _e($category->term_id); ?>" type="text" value="<?php echo (empty($my_auth_user)) ? '' : $my_auth_user; ?>" size="40" aria-required="true" /> </td> <td class='pass' NOWRAP> <input class="help" title="半角英数でパスワードを・・・" name="my_auth_data_[<?php _e($category->term_id); ?>][2]" id="my_auth_pass_<?php _e($category->term_id); ?>" type="text" value="<?php echo (empty($my_auth_pass)) ? '' : $my_auth_pass; ?>" size="40" /> </td> </tr> <?php $cnt++; $children = get_categories(array('parent' => $category->cat_ID)); foreach ($children as $child) { $my_auth_user = esc_attr($my_auth_data[$child->term_id]['user']); $my_auth_pass = esc_attr($my_auth_data[$child->term_id]['pass']); $checked = ''; if ( $my_auth_data[$child->term_id] ) { $checked = ' checked="checked"'; } ?> <tr id="tag-<?php _e($child->term_id); ?>"<?php if ($cnt % 2 == 0) _e(' class="alternate"'); ?>> <th scope="row" class="check-column"> <input id="my_auth_dirs_<?php _e($child->term_id); ?>" type="checkbox" name="my_auth_data_[<?php _e($child->term_id); ?>][0]" value="YES" <?php _e($checked); ?> /> </th> <td class='name' NOWRAP> <label for="my_auth_dirs_<?php _e($child->term_id); ?>"><strong>? <?php _e($child->name); ?></strong></label> </td> <td class='slug' NOWRAP> <?php _e($child->slug); ?> </td> <td class='user' NOWRAP> <input class="help" title="半角英数でユーザ名を・・・" name="my_auth_data_[<?php _e($child->term_id); ?>][1]" id="my_auth_user_<?php _e($child->term_id); ?>" type="text" value="<?php echo (empty($my_auth_user)) ? '' : $my_auth_user; ?>" size="40" aria-required="true" /> </td> <td class='pass' NOWRAP> <input class="help" title="半角英数でパスワードを・・・" name="my_auth_data_[<?php _e($child->term_id); ?>][2]" id="my_auth_pass_<?php _e($child->term_id); ?>" type="text" value="<?php echo (empty($my_auth_pass)) ? '' : $my_auth_pass; ?>" size="40" /> </td> </tr> <?php $cnt++; }//$children }// $categories ?> </tbody> </table> <input type="submit" name="Submit" class="button-primary" value="変更を保存" /> </form> </div> <?php }// function auth_setting_page //BASIC認証 function Basic_Authentication( $auth_list , $realm="Restricted Area" , $failed_text="ログインできませんでした" ) { if (isset($_SERVER['PHP_AUTH_USER']) and isset($auth_list[$_SERVER['PHP_AUTH_USER']])) { if ( $auth_list[$_SERVER['PHP_AUTH_USER']] == $_SERVER['PHP_AUTH_PW'] ) { /* $value = 1; - $timeout = 0; - setcookie('BASIC',$value,$timeout,'/'); */ return $_SERVER['PHP_AUTH_USER']; } } header('WWW-Authenticate: Basic realm="'.$realm.'"'); header('HTTP/1.0 401 Unauthorized'); header('Content-type: text/html; charset='.mb_internal_encoding()); exit($failed_text); } // カテゴリ認証チェック function Check_Categories_Authentication() { //管理画面、ログイン画面は除外 if ( !is_admin() && !(basename($_SERVER['PHP_SELF']) == 'wp-login.php') ) { $my_auth_data = array(); $categories = get_categories(); // 全カテゴリ取得 $my_auth_data = get_option('my_auth_data'); foreach ($categories as $category) { $search = "//{$category->slug}//"; // 参照カテゴリ? if ( preg_match($search, $_SERVER['REQUEST_URI']) ) { // Basic認証するカテゴリ? if ( $my_auth_data[$category->cat_ID] ) { $my_auth_user = esc_attr($my_auth_data[$category->cat_ID]['user']); $my_auth_pass = esc_attr($my_auth_data[$category->cat_ID]['pass']); $this->Basic_Authentication( array( $my_auth_user => $my_auth_pass ) ); } break; } } } } } // 削除 ※削除はクラスにおいても、動作しない・・・ if( function_exists('register_uninstall_hook') ) { register_uninstall_hook( __FILE__ , 'Uninstall_Categories_Basic_Auth' ); } function Uninstall_Categories_Basic_Auth () { delete_option( 'my_auth_data' ); delete_option( 'my_auth_dirs' ); delete_option( 'my_auth_user' ); delete_option( 'my_auth_pass' ); } ?>
試したこと
正常に動作しているデモ環境はあるのですが、比較検証してもwp配下の階層のファイルに差異は見られなかった。
home直下のファイルに原因があるのかとも思いましたが、具体的行動がわかりません。
個人的に持っているサーバー(エックスサーバー)にHPのパッケージを設置し動くか検証→正常ならず
補足情報(FW/ツールのバージョンなど)
何の情報を他に開示すれば良いかわからないため、情報が不足しているかもしてませんが、そのさいは何が足りないか教えていただければと思います。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー