Support

Home Forums WP User Integration Automatically generated password after registering

Automatically generated password after registering

Posted: May 16, 2016 at 4:26 am


robbstcs

May 16, 2016 at 4:26 am

Hi,

I’ve found a topic that looks like it does what I need it to do but I think it’s for EE3 and doesnt work in EE4.

https://eventespresso.com/topic/create-username-password-when-registering-for-an-event/

Is there a way of doing this in EE4. Currently customers get a email with a link in to ‘set’ a password. but setting the password doesnt work.


Tony

  • Support Staff

May 16, 2016 at 5:39 am

HI there,

Its now considered bad practice to send the password to the user via un-secure email.

WordPress core changed how users are created so now the user must use the reset password link provided within the email WP sends out when EE creates the user.

What happens when the user click on the set password link?

Is there an event I can run a registration on to view an example?


robbstcs

May 16, 2016 at 5:44 am

sure, thanks Tony.

When the user gets sent the email and clicks on the link you get the reset password page but immediately it says:

‘Sorry, your password must have a minimum of 7 characters’
Then when you ignore that and try to set a password or use the password generated, the button doesn’t work and it doesn’t actually set a password.

http://contentmanagementwebsite.co.uk/keep_active/events/test-week-event/


Tony

  • Support Staff

May 16, 2016 at 6:01 am

Are you running any caching plugins?

Does your host run any server side caching?

I looks like the form is being submitted with no values.


robbstcs

May 16, 2016 at 6:16 am

Not that I know of, And we’ve switched off the caching by our host as it was conflicting with development before.

There has been some actions added to the child themes function php to get the registration forms working. and a plugin for woocommerce password strength.

//1. Add a new form element...
add_action( 'register_form', 'myplugin_register_form' );
function myplugin_register_form() {

    $first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';
	$last_name = ( ! empty( $_POST['last_name'] ) ) ? trim( $_POST['last_name'] ) : '';
        
        ?>
        <p class="form-row form-row-first">
            <label for="first_name"><?php _e( 'First Name', 'mydomain' ) ?><span class="required"> *</span><br />
                <input type="text" name="first_name" id="first_name" class="input-text" value="<?php echo esc_attr( wp_unslash( $first_name ) ); ?>" size="25" /></label>
        </p>
		 <p class="form-row form-row-last">
            <label for="last_name"><?php _e( 'Last Name', 'mydomain' ) ?><span class="required"> *</span><br />
                <input type="text" name="last_name" id="last_name" class="input-text" value="<?php echo esc_attr( wp_unslash( $last_name ) ); ?>" size="25" /></label>
        </p>
		<p style="display: inline-block; font-size: 0.8em; margin-bottom: 10px;">
			* By registering for an account, You agree to be signed up to our mailing list. You may unsubscribe at any time.
		</p><br/>
        <?php
    }

    //2. Add validation. In this case, we make sure first_name is required.
    add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
    function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
        
        if ( empty( $_POST['first_name'] ) || ! empty( $_POST['first_name'] ) && trim( $_POST['first_name'] ) == '' ) {
            $errors->add( 'first_name_error', __( '<strong>ERROR</strong>: You must include a first name.', 'mydomain' ) );
        }
		if ( empty( $_POST['last_name'] ) || ! empty( $_POST['last_name'] ) && trim( $_POST['last_name'] ) == '' ) {
            $errors->add( 'last_name_error', __( '<strong>ERROR</strong>: You must include a last name.', 'mydomain' ) );
        }

        return $errors;
    }
	//2.1. Add validation for woocommerce register form.
	function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
		if ( isset( $_POST['first_name'] ) && empty( $_POST['first_name'] ) ) {
			$validation_errors->add( 'first_name_error2', __( 'First name is required!', 'woocommerce' ) );
		}

		if ( isset( $_POST['last_name'] ) && empty( $_POST['last_name'] ) ) {
			$validation_errors->add( 'last_name_error2', __( 'Last name is required!.', 'woocommerce' ) );
		}
	}
	add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );

    //3. Finally, save our extra registration user meta.
    add_action( 'user_register', 'myplugin_user_register' );
    function myplugin_user_register( $user_id ) {
        if ( ! empty( $_POST['first_name'] ) ) {
            update_user_meta( $user_id, 'first_name', trim( $_POST['first_name'] ) );
        }
		if ( ! empty( $_POST['last_name'] ) ) {
            update_user_meta( $user_id, 'last_name', trim( $_POST['last_name'] ) );
        }
    }  
	
	//Add hooks to change the password strength messages.
	add_action( 'wp_enqueue_scripts', 'my_strength_meter_localize_script' );
	function my_strength_meter_localize_script() {
		wp_localize_script( 'password-strength-meter', 'pwsL10n', array(
			'empty'    => __( 'Password is empty!', 'theme-domain' ),
			'short'    => __( 'Weak', 'theme-domain' ),
			'bad'      => __( 'Okay ', 'theme-domain' ),
			'good'     => __( 'Good', 'theme-domain' ),
			'strong'   => __( 'Excellent', 'theme-domain' ),
			'mismatch' => __( 'Password mismatch', 'theme-domain' )
		) );
	}

	add_filter( 'wc_password_strength_meter_params', 'my_strength_meter_custom_strings' );
	function my_strength_meter_custom_strings( $data ) {
		$data_new = array(
			'i18n_password_error'   => esc_attr__( 'We recommend a stronger password', 'theme-domain' ),
			'i18n_password_hint'    => esc_attr__( 'The password should be at least seven characters long.', 'theme-domain' )
		);

		return array_merge( $data, $data_new );
	}

	function change_register_url($link){
		$link = "<a href='http://contentmanagementwebsite.co.uk/keep_active/my-account/'>Register</a>";
		/*
			Change wp registration url
		*/
		return str_replace(site_url('wp-login.php?action=register', 'login'),site_url('register', 'login'),$link);
	}
	add_filter('register','change_register_url');
	


robbstcs

May 16, 2016 at 7:24 am

Ahhh, Plugin was causing the problem, seems to be resetting now.

Woocommerce Enforce Strong Password


robbstcs

May 16, 2016 at 7:45 am

I wonder if there is a way of letting the users set their passwords when they purchase an event ticket? Can this be done with EE wp user intergration?

Thanks.


Josh

  • Support Staff

May 16, 2016 at 10:10 am

Hi there,

It turns out that Event Espresso 4’s WP User Integration add-on doesn’t have a feature where it lets the ticket buyer set the password when they buy the ticket.

The support post ‘Automatically generated password after registering’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso