Last active
December 28, 2015 03:48
-
-
Save kurudrive/7437271 to your computer and use it in GitHub Desktop.
[WP] パスワード無しで特定多数のIDを既に持ったユーザーをログインさせる
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 | |
/* | |
※もっとスマートな実装方法があれば教えてください。 | |
【1】 閲覧ユーザー用のIDを1つ発行 | |
予め | |
ID : member | |
パスワード : memberpass | |
のユーザーを購読者権限で発行 | |
【2】 ユーザーのリストはpost_contentやoptionなどに , 区切りで登録しておく | |
【3】 テキストを入力させてgetに投げてページを再読み込み | |
【4】 ログインコードリストを配列に格納 | |
【5】 入力されたコードがログインコードリストにあった場合は | |
予め用意したログインIDとパスワードで自動的にログイン | |
*/ | |
?> | |
<form name="logincodeform" id="logincodeform" action="" method="get"> | |
<input type="text" name="login_code" id="login_code" class="input" value="" size="20" /> | |
<input type="submit" class="" value="認証" /> | |
</form> | |
<?php | |
// パラメターからcodeを取得 | |
if(isset($_GET['login_code'])) { | |
$login_code = $_GET['login_code']; | |
// ログイン判定用の変数を設定 | |
$loginCodeJudge = ''; | |
// オプションで作成したフィールドにログインコードを保存した場合 | |
// $optionsArry = get_option( 'login_code_options' ); | |
// $optionsArry = $optionsArry['login_code_arry']; | |
// 記事本文欄にログインコードを保存する場合 | |
if ( have_posts() ) while ( have_posts() ) : the_post(); | |
$optionsArry = $post->post_content; | |
endwhile; | |
// 文字列を配列にして$loginIDsに格納 | |
$loginIDs = explode(",", $optionsArry); | |
foreach ($loginIDs as $key => $value) { | |
// 入力された値がログインIDリストの中にあった場合 | |
if ($login_code == $value) { ?> | |
<form name="loginform" id="loginform" action="<?php echo site_url(); ?>/wp-login.php" method="post"> | |
<input type="hidden" name="log" id="user_login" class="input" value="member" size="20" /> | |
<input type="hidden" name="pwd" id="user_pass" class="input" value="memberpass" size="20" /> | |
<input type="hidden" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="ログイン" /> | |
<input type="hidden" name="redirect_to" value="ログインしたらリダイレクトさせるURL" /> | |
<SCRIPT language="JavaScript">document.loginform.submit();</SCRIPT> | |
</form> | |
<?php } else { | |
// 違っていたらログイン判定用の変数に"miss"を代入 | |
$loginCodeJudge = "miss"; | |
} // if ($login_code == $value) | |
} // foreach | |
if ($loginCodeJudge = "miss") | |
echo '<p class="alert">ログインコードが違います</p>'; | |
} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment