Password Field on Registration Form

Share This Post

Password Field on Registration Form

We usually get into wordpress site and don’t get password field registration form but it’s far way easier to access through this code snippet to get it now.

Let’s check how it is working…

Snippet 1: Adding password field to the form

This snippet will help you to add password field to the form.

				
					/** 
  * Add password field to the form
  */
add_action( 'register_form', 'add_pass_field_to_register' );
function add_pass_field_to_register() {
	$pass = ( ! empty( $_POST['user_pass'] ) ) ? $_POST['user_pass'] : '';
    ?><p>
    	<label for="user_pass"><?php _e( 'Password', CRF_TEXT_DOMAIN ) ?>
    		<input type="text" name="user_pass" id="user_pass" class="input" value=" 
    		<?php echo $pass; ?>" size="25" />
    	</label>
    </p><?php
}

				
			

Snippet 2: Validating user’s password

The process of validating your password through this code snippet.

				
					/** Validate user password
   
  * @param $errors
  * @param $sanitized_user_login
  * @param $user_email
  * @return mixed
  */
add_filter( 'registration_errors', 'validate_pass_register_field', 10, 3 );
function validate_pass_register_field( $errors, $sanitized_user_login, $user_email ) {
	if ( empty( $_POST['user_pass'] ) || ! empty( $_POST['user_pass'] ) && trim( 
		$_POST['user_pass'] ) == '' ) {
		$errors->add( 'user_pass_error', sprintf('<strong>%s</strong>: %s',__( 
             'ERROR', CRF_TEXT_DOMAIN ),__( 'You must include password.', 
              CRF_TEXT_DOMAIN ) ) );
        }

        return $errors;
}
				
			

Snippet 3: Saving user’s password

Here this code snippet saves your password to the registration form easily.

				
					* Save user password
   *
   * @param $user_id
   */
add_action( 'user_register', 'save_user_password' );
function save_user_password( $user_id ) {
      if ( ! empty( $_POST['user_pass'] ) ) {
            $password = trim( $_POST['user_pass'] );
            wp_set_password( $password, $user_id );
      }
				
			

Conclusion

So, All you need to add this code snippet to your theme functions.php file. Or download the plugin and install it on your server to know admin user ID easily. Enjoy! 

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

How to get admin user ID

Share This Post How to get admin User ID? It’s been really difficult for many to get back the admin user ID but it’s so

Award GamiPress on RCPro Membership Renewal

Share This Post Award GamiPress on RCPro Membership Renewal Do you think users can also be awarded points/badges/ranks while RCPro Membership renewal? Yes, you can

Custom Message with myCRED Transfer

Share This Post Custom Message with myCRED Transfer MyCred assigns different points to the users but it’s been sometime noticed that the users want to

Want To Know About Our Services?

small_c_popup-300x296

Let’s Talk To Us With Your Concerns

    Once you send the details, we will be shortly back to you. Thanks!

    small_c_popup-300x296

    Become a valuable part of Team LDninjas

    small_c_popup-300x296

    Be updated with new release by LDninjas!