1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Wordpressのパスワード再発行時に文字数制限を掛ける

Last updated at Posted at 2014-11-01

wordpressのユーザ登録権限を一般開放する際、
(たとえば会員制サイトを制作する時など)
パスワード再発行時に使用するフォームにて、
入力可能な文字数に制限を掛けるスクリプトを作った。

wordpressの仕様では、ユーザが設定できるパスワードについて
「7文字以上でご入力ください」とヒント欄にて触れているものの、
実際には制限が掛かってない。自由。
だが許されざる自由も、まれにある。

Login Security Solutionプラグインを導入する手もあるが、
各々に影響の出るシステムを導入するよりは、
登録画面のみにjQueryを走らせた方が楽かなと。

という訳で以下をfunctions.phpに記述。

function edit_resetpass_login(){
  $input_act = filter_input(INPUT_GET, 'action');
  if($input_act === 'rp' || $input_act === 'resetpass'){
?>
<script type="text/javascript">
jQuery(function(){
  var btSub = jQuery('#wp-submit');
  jQuery('#pass2').keyup(function() {
    if(jQuery(this).val().length > 6){
      btSub.removeAttr('disabled').val('パスワードを再設定');
    }else{
      btSub.attr('disabled', 'disabled').val('7文字以上ご入力ください');
    }
  }).keyup();
});
</script>
<?php
  }
}
add_action('login_head', 'edit_resetpass_login');

注意

プロフィール更新などを一般公開している環境では、そこにも上記スクリプトを読ませなければならない。
下記の対策が必要。

  • php部の分岐とadd_actionを用いて、プロフィール更新画面のみに適用されるよう修正
  • JS部のjQuery('#wp-submit')をjQuery('#submit')に変更し、0文字でもボタンが押せるように修正
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?