2017-06-20 4 views
1

私は、ワードプレス登録フォームのユーザー名を非表示にする良い方法をお探しです。現在、私はそれを稼働させていますが、フォームはユーザーが「あなたの電子メールアドレスを入力してください」と再度尋ねるので、ユーザーフレンドリーではありません。これはsafetyworks.com/loginに見ることができます。ここでワードプレス登録時のユーザー名の非表示

は、私のコードの上半分である:

<?php 
$current_email = isset($_POST['user_email']) ? $_POST['user_email'] : ''; 
$current_username = $current_email; 

?> 

<?php if ($this->should_print_form()) : ?> 

    <?php $this->print_form_header(); ?> 

    <div class="row clearfix"> 
     <div class="col-sm-10 col-md-8 col-sm-offset-1 col-md-offset-2"> 
      <div class="panel panel-primary panel-border top"> 
       <div class="panel-heading"> 
        <span class="panel-title fs-lg"><i class="fa fa-edit"></i> <?php _e('Create an account', 'cuarlf'); ?></span> 
       </div> 

       <div class="panel-body"> 
        <div class="form-group mb-lg"> 
         <label for="user_email" class="control-label top-label"><?php _e('Email Address', 'cuarlf'); ?></label> 
         <div class="row clearfix"> 
          <div class="col-xs-12"> 
           <span class="append-icon right"><i class="field-icon fa fa-asterisk text-muted"></i></span> 
           <input class="form-control" type="email" name="user_email" id="user_email" value="<?php echo esc_attr($current_email); ?>"> 
           <input class="form-control" type="hidden" name="user_login" id="user_login" value="<?php echo $current_username; ?>"> 
             </div> 
         </div> 
        </div> 

ので、ユーザ名を隠すために良い方法はありますか?私はスマートWPのログインを使用してみましたが、そのワードプレスは依然としてユーザー名を指定したいと思います。私はSmart WPログインが約束した効果と同様の機能を試しましたが、失敗しました。

私はWP-Customer Areaプラグインにこの問題の原因となっている機能があることがわかりました。

public static function register_new_user($user_login, $user_email) 
     { 
      global $wpdb; 

      $errors = new WP_Error(); 

      $sanitized_user_login = sanitize_user($user_login); 
      $user_email = apply_filters('user_registration_email', $user_email); 

      // Check the username 
      if ($sanitized_user_login == '') 
      { 
       $errors->add('empty_username', __('Please enter a username.', 'cuarlf')); 
      } 
      elseif (!validate_username($user_login)) 
      { 
       $errors->add('invalid_username', __('Sorry. Please enter a username using only lowercase letters and numbers.', 'cuarlf')); 
       $sanitized_user_login = ''; 
      } 
      elseif (username_exists($sanitized_user_login)) 
      { 
       $errors->add('username_exists', __('This username is already registered. Please choose another one.', 'cuarlf')); 
      } 

      // Check the email address 
      if ($user_email == '') 
      { 
       $errors->add('empty_email', __('Please type your email address.', 'cuarlf')); 
      } 
      elseif (!is_email($user_email)) 
      { 
       $errors->add('invalid_email', __('The email address isn&#8217;t correct.', 'cuarlf')); 
       $user_email = ''; 
      } 
      elseif (email_exists($user_email)) 
      { 
       $errors->add('email_exists', __('This email is already registered, please choose another one.', 'cuarlf')); 
      } 

      do_action('register_post', $sanitized_user_login, $user_email, $errors); 

      $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email); 

      if ($errors->get_error_code()) 
      { 
       return $errors; 
      } 

      $user_pass = wp_generate_password(12, false); 
      $user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email); 
      if (!$user_id) 
      { 
       $errors->add('registerfail', 
        sprintf(__('Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'cuarlf'), get_option('admin_email'))); 

       return $errors; 
      } 

      update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag. 


      // Generate something random for a key... 
      $activation_key = wp_generate_password(20, false); 
      do_action('retrieve_password_key', $user_login, $activation_key); 

      // Now insert the new md5 key into the db 
      $wpdb->update($wpdb->users, array('user_activation_key' => $activation_key), array('user_login' => $user_login)); 

      // Send notifications 
      $user = get_userdata($user_id); 
      self::new_user_notification_admin($user); 
      self::new_user_notification($user, $activation_key); 

      return $user_id; 
     } 

問題は、フォームが電子メールアドレスが空白だと思われる理由です。

+0

これは私がいない成功を収めてみました機能でした - https://wordpress.stackexchange.com/questions/52302/is-it-possible-to-remove-username-field-from-the-registration-もしかするとページがあれば – timrosenthal

答えて

0

私はこの方法をあまりにも多く考えすぎました!

、それがどのように見えるように、フォームのためにやらなければならないことは、USER_LOGINためのダミー値に入れている:私は$current_username = $current_email;削除ページの上部に

<input class="form-control" type="hidden" name="user_login" id="user_login" value="ABC">

フォーム提出コードでは、フォームuse $_POST['user_email']をuser_login値として使用します。

if (isset($_POST['user_email'])) 
      { 

       $user_email = $_POST['user_email']; 
     $user_login = $_POST['user_email']; 

       // Check captch if enabled 
       if (class_exists("ReallySimpleCaptcha")) 
       { 
        $captcha_instance = new ReallySimpleCaptcha(); 

        if (!isset($_POST['cuar_captcha_prefix']) || !isset($_POST['captcha'])) 
        { 
         $this->form_errors[] = new WP_Error('captcha', 
          __("You must write the code displayed in the image above.", 'cuarlf')); 

         return; 
        } 
        else 
        { 
         $prefix = $_POST['cuar_captcha_prefix']; 
         $code = $_POST['captcha']; 

         $captcha_checked = $captcha_instance->check($prefix, $code); 
         $captcha_instance->remove($prefix); 
         $captcha_instance->cleanup(); 

         if (!$captcha_checked) 
         { 
          $this->form_errors[] = new WP_Error('captcha', __("The code you entered is not correct.", 'cuarlf')); 

          return; 
         } 
        } 
       } 

       $errors = CUAR_WPLoginHelper::register_new_user($user_login, $user_email); 
       if (is_wp_error($errors)) 
       { 
        $this->form_errors[] = $errors; 

        return; 
       } 
      } 
      else 
      { 
       $this->form_errors[] = new WP_Error('user_login', __("You must enter a valid username and a valid email address.", 'cuarlf')); 

       return; 
      } 

      $lf_addon = $this->plugin->get_addon('login-forms'); 
      $this->form_messages[] = sprintf(__('An email has been sent with the instructions to activate your account. ' 
       . 'You can then go to the <a href="%1$s" class="alert-link">login page</a>', 'cuarlf'), $lf_addon->get_login_url()); 
      $this->should_print_form = false; 
     } 
関連する問題