I
I
Ingvar Von Bjork2020-08-21 04:50:59
WordPress
Ingvar Von Bjork, 2020-08-21 04:50:59

How to create your own registration page without entering a login?

We have the simplest bzer registration page on WP:

<form id="registerform" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post">
  <p>
    <label for="user_login">
      Имя пользователя<br>
      <input type="text" name="user_login" id="user_login" class="input" value="" size="20" style="">
    </label>
  </p>
  <p>
    <label for="user_email">
      E-mail<br>
      <input type="email" name="user_email" id="user_email" class="input" value="" size="25">
    </label>
  </p>

  <p id="reg_passmail">Подтверждение регистрации будет отправлено на ваш e-mail.</p>

  <br class="clear">
  <input type="hidden" name="redirect_to" value="">

  <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Регистрация"></p>
</form>

Actually, how can you remove the username input field and still retain the ability to register? Simply deleting the field from the form will not work, because WP will swear at his absence

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2020-08-21
@Asokr

The beauty of WP is that the network has an answer to almost every Wishlist, you need to google in English ...
I did this:
Step-1: Hide the registration field

add_action('login_head', function(){
?>
    <style>
        #registerform > p:first-child{
            display:none;
        }
    </style>

    <script type="text/javascript" src="<?php echo site_url('/wp-includes/js/jquery/jquery.js'); ?>"></script>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $('#registerform > p:first-child').css('display', 'none');
        });
    </script>
<?php
});

Step-2: Remove the WP Standard Error
//Remove error for username, only show error for email only.
add_filter('registration_errors', function($wp_error, $sanitized_user_login, $user_email){
    if(isset($wp_error->errors['empty_username'])){
        unset($wp_error->errors['empty_username']);
    }

    if(isset($wp_error->errors['username_exists'])){
        unset($wp_error->errors['username_exists']);
    }
    return $wp_error;
}, 10, 3);

Step-3: Enter the user's mail instead of login
add_action('login_form_register', function(){
    if(!isset($_POST['user_login']) && isset($_POST['user_email']) && !empty($_POST['user_email'])){
        $_POST['user_login'] = $_POST['user_email'];
    }
});

We add all this to functions.php of course.
Source:
https://wordpress.stackexchange.com/questions/5230...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question