女武神的终末第三季免费观看,国产精品va无码二区,欧美日韩在线视频观看,国产在线观看网站

wordpress開發(fā)教程:優(yōu)化用戶注冊體驗(yàn)(自定義密碼)

2015-04-03 wordpress教程
  • 文章介紹
  • 快速入門
  • 評價&建議

今天有位小伙伴在群中詢問wordpress新用戶注冊顯示密碼的問題,由于wordpress默認(rèn)的是不讓用戶自己去填寫密碼的,而是系統(tǒng)自動給用戶生成一個密碼并且發(fā)送到用戶郵箱,相對來說可能有些用戶會不習(xí)慣,今天就來教大家優(yōu)化wordpress的用戶注冊體驗(yàn),讓用戶自己設(shè)置賬戶密碼,其實(shí)很簡單只需要在主題的function.php加上以下代碼:

  1. <?php  
  2. add_action( 'register_form', 'v7v3_show_register' );  
  3. function ztmao_show_register(){  
  4. ?>  
  5.     <p>  
  6.         <label for="password">密碼:<br/>  
  7.         <input id="password" class="input" type="password" tabindex="30" size="25" value="" name="password" />  
  8.         </label>  
  9.     </p>  
  10.     <p>  
  11.         <label for="repeat_password">確認(rèn)密碼<br/>  
  12.         <input id="repeat_password" class="input" type="password" tabindex="40" size="25" value="" name="repeat_password" />  
  13.         </label>  
  14.     </p>  
  15.     <p>  
  16.         <label for="are_you_human" style="font-size:11px">挖掘機(jī)技術(shù)哪家強(qiáng)?(藍(lán)翔)<br/>  
  17.         <input id="are_you_human" class="input" type="text" tabindex="40" size="25" value="" name="are_you_human" />  
  18.         </label>  
  19.     </p>  
  20. <?php  
  21. }  
  22. add_action( 'register_post', 'ts_check_extra_register_fields', 10, 3 );  
  23. function ts_check_extra_register_fields($login$email$errors) {  
  24.     if ( $_POST['password'] !== $_POST['repeat_password'] ) {  
  25.         $errors->add( 'passwords_not_matched', "<strong>ERROR</strong>: 兩次密碼不一致" );  
  26.     }  
  27.     if ( strlen$_POST['password'] ) < 8 ) {  
  28.         $errors->add( 'password_too_short', "<strong>ERROR</strong>: 密碼長度小于8位!" );  
  29.     }  
  30.     if ( $_POST['are_you_human'] !== '藍(lán)翔' ) {  
  31.         $errors->add( 'not_human', "<strong>ERROR</strong>: 回答錯誤,請重新填寫注冊信息!" );  
  32.     }  
  33. }  

為了保證不被注冊機(jī)騷擾此代碼中還自帶了一個驗(yàn)證問題字段,防止注冊機(jī)批量注冊垃圾用戶。雖然讓用戶可以自己填寫密碼,但是有些用戶更加喜歡讓系統(tǒng)為他生成密碼,為了給這些用戶提供方便,我們可以判斷下當(dāng)前用戶注冊時是否填了密碼,如果沒填再讓系統(tǒng)生成一個,代碼如下:

  1. add_action( 'user_register', 'ztmao_register_extra_pass', 100 );  
  2. function ztmao_register_extra_pass( $user_id$password=""$meta=array() ){  
  3.     $userdata = array();  
  4.     $userdata['ID'] = $user_id;  
  5. if$_POST['password'] ){  
  6.     $userdata['user_pass'] = $_POST['password'];  
  7. }  
  8.     wp_update_user($userdata);  
  9. }  
  10.        
  11. /*如果強(qiáng)制用戶輸入密碼,則可將此段代碼的注釋去除 
  12. add_action('admin_init', 'remove_default_password_nag'); 
  13. function remove_default_password_nag() { 
  14.     global $user_ID; 
  15.     delete_user_setting('default_password_nag', $user_ID); 
  16.     update_user_option($user_ID, 'default_password_nag', false, true); 
  17. } 
  18. */  

當(dāng)然為了給用戶更好的體驗(yàn),我們可以在注冊框下方加個提示,代碼如下:

  1. add_filter( 'gettext', 'v7v3_edit_text' );  
  2. function ztmao_edit_text( $text ) {  
  3.     if ( $text == 'A password will be e-mailed to you.' ) {  
  4.         $text = '如果您不填寫密碼,系統(tǒng)將為您生成一個密碼, 并發(fā)送至您的郵箱。';  
  5.     }  
  6.     return $text;  
  7. }  
0 0

企業(yè)建站推薦正版商業(yè)主題,國內(nèi)專業(yè)團(tuán)隊(duì)開發(fā),完善售后,是您不二選擇。

正版主題商店

主題貓WP建站,累計幫助1300+客戶成功建站,為站長提供支持!

立刻開啟你的建站之旅
QQ在線客服

服務(wù)熱線

wordpress建站咨詢