myaccount registration added check for auto generate password option

This commit is contained in:
splashingpixels 2014-04-01 19:45:25 -07:00 committed by Mike Jolley
parent ce2f2e1c3d
commit afc17dad40
3 changed files with 23 additions and 11 deletions

View File

@ -848,16 +848,22 @@ class WC_Form_Handler {
wp_verify_nonce( $_POST['register'], 'woocommerce-register' ); wp_verify_nonce( $_POST['register'], 'woocommerce-register' );
if ( 'no' == get_option( 'woocommerce_registration_generate_username' ) ) { if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) {
$_username = $_POST['username']; $_username = $_POST['username'];
} else { } else {
$_username = ''; $_username = '';
} }
if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) {
$_password = $_POST['password'];
} else {
$_password = '';
}
try { try {
$validation_error = new WP_Error(); $validation_error = new WP_Error();
$validation_error = apply_filters( 'woocommerce_process_registration_errors', $validation_error, $_username, $_POST['password'], $_POST['email'] ); $validation_error = apply_filters( 'woocommerce_process_registration_errors', $validation_error, $_username, $_password, $_POST['email'] );
if ( $validation_error->get_error_code() ) { if ( $validation_error->get_error_code() ) {
throw new Exception( '<strong>' . __( 'Error', 'woocommerce' ) . ':</strong> ' . $validation_error->get_error_message() ); throw new Exception( '<strong>' . __( 'Error', 'woocommerce' ) . ':</strong> ' . $validation_error->get_error_message() );
@ -872,7 +878,7 @@ class WC_Form_Handler {
$username = ! empty( $_username ) ? wc_clean( $_username ) : ''; $username = ! empty( $_username ) ? wc_clean( $_username ) : '';
$email = ! empty( $_POST['email'] ) ? wc_clean( $_POST['email'] ) : ''; $email = ! empty( $_POST['email'] ) ? wc_clean( $_POST['email'] ) : '';
$password = ! empty( $_POST['password'] ) ? wc_clean( $_POST['password'] ) : ''; $password = wc_clean( $_password );
// Anti-spam trap // Anti-spam trap
if ( ! empty( $_POST['email_2'] ) ) { if ( ! empty( $_POST['email_2'] ) ) {

View File

@ -24,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @return bool * @return bool
*/ */
function wc_disable_admin_bar( $show_admin_bar ) { function wc_disable_admin_bar( $show_admin_bar ) {
if ( apply_filters( 'woocommerce_disable_admin_bar', get_option( 'woocommerce_lock_down_admin', 'yes' ) == 'yes' ) && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_woocommerce' ) ) ) { if ( apply_filters( 'woocommerce_disable_admin_bar', get_option( 'woocommerce_lock_down_admin', 'yes' ) === 'yes' ) && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_woocommerce' ) ) ) {
$show_admin_bar = false; $show_admin_bar = false;
} }
@ -53,7 +53,7 @@ function wc_create_new_customer( $email, $username = '', $password = '' ) {
} }
// Handle username creation // Handle username creation
if ( 'no' == get_option( 'woocommerce_registration_generate_username' ) || ! empty( $username ) ) { if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) || ! empty( $username ) ) {
$username = sanitize_user( $username ); $username = sanitize_user( $username );
@ -78,11 +78,13 @@ function wc_create_new_customer( $email, $username = '', $password = '' ) {
} }
// Handle password creation // Handle password creation
if ( 'yes' == get_option( 'woocommerce_registration_generate_password' ) && empty( $password ) && ! isset( $_POST['register'] ) ) { if ( 'yes' === get_option( 'woocommerce_registration_generate_password' ) && empty( $password ) ) {
$password = wp_generate_password(); $password = wp_generate_password();
$password_generated = true; $password_generated = true;
} elseif ( empty( $password ) ) { } elseif ( empty( $password ) ) {
return new WP_Error( 'registration-error', __( 'Please enter an account password.', 'woocommerce' ) ); return new WP_Error( 'registration-error', __( 'Please enter an account password.', 'woocommerce' ) );
} else { } else {
$password_generated = false; $password_generated = false;
} }

View File

@ -66,7 +66,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<?php do_action( 'woocommerce_register_form_start' ); ?> <?php do_action( 'woocommerce_register_form_start' ); ?>
<?php if ( get_option( 'woocommerce_registration_generate_username' ) === 'no' ) : ?> <?php if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) : ?>
<p class="form-row form-row-wide"> <p class="form-row form-row-wide">
<label for="reg_username"><?php _e( 'Username', 'woocommerce' ); ?> <span class="required">*</span></label> <label for="reg_username"><?php _e( 'Username', 'woocommerce' ); ?> <span class="required">*</span></label>
@ -80,10 +80,14 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<input type="email" class="input-text" name="email" id="reg_email" value="<?php if ( ! empty( $_POST['email'] ) ) echo esc_attr( $_POST['email'] ); ?>" /> <input type="email" class="input-text" name="email" id="reg_email" value="<?php if ( ! empty( $_POST['email'] ) ) echo esc_attr( $_POST['email'] ); ?>" />
</p> </p>
<p class="form-row form-row-wide"> <?php if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) : ?>
<label for="reg_password"><?php _e( 'Password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="password" class="input-text" name="password" id="reg_password" value="<?php if ( ! empty( $_POST['password'] ) ) echo esc_attr( $_POST['password'] ); ?>" /> <p class="form-row form-row-wide">
</p> <label for="reg_password"><?php _e( 'Password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="password" class="input-text" name="password" id="reg_password" value="<?php if ( ! empty( $_POST['password'] ) ) echo esc_attr( $_POST['password'] ); ?>" />
</p>
<?php endif; ?>
<!-- Spam Trap --> <!-- Spam Trap -->
<div style="left:-999em; position:absolute;"><label for="trap"><?php _e( 'Anti-spam', 'woocommerce' ); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div> <div style="left:-999em; position:absolute;"><label for="trap"><?php _e( 'Anti-spam', 'woocommerce' ); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div>