0

All, I've created a custom registration form on www.safetyworks.com/login.

The problem is the password field. It allows the user to submit the form no problem but the initial password the user puts in does not work. The user has to do a password reset in order for it work. Here is the registration fields code to update the user meta data (which I'm using in a custom plugin):

 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'] ) );
        }
        if ( ! empty( $_POST['job_title'] ) ) {
            update_user_meta( $user_id, 'job_title', trim( $_POST['job_title'] ) );
        }
        if ( ! empty( $_POST['billing_company'] ) ) {
            update_user_meta( $user_id, 'billing_company', trim( $_POST['billing_company'] ) );
        }
        if ( ! empty( $_POST['address'] ) ) {
            update_user_meta( $user_id, 'address', trim( $_POST['address'] ) );
        }
        if ( ! empty( $_POST['billing_city'] ) ) {
            update_user_meta( $user_id, 'billing_city', trim( $_POST['billing_city'] ) );
        }
        if ( ! empty( $_POST['state'] ) ) {
            update_user_meta( $user_id, 'state', trim( $_POST['state'] ) );
        }
        if ( ! empty( $_POST['billing_postcode'] ) ) {
            update_user_meta( $user_id, 'billing_postcode', trim( $_POST['billing_postcode'] ) );
        }
        if ( ! empty( $_POST['phone_number'] ) ) {
            update_user_meta( $user_id, 'phone_number', trim( $_POST['phone_number'] ) );
        }
        if ( ! empty( $_POST['password'] ) ) {
            update_user_meta( $user_id, 'password', trim( $_POST['password'] ) );
        }
    }

What am I missing? Like I said, all other fields seem to be fine.

  • Check your db field is same or different – Zeshan Nov 2 '17 at 13:10
0

The password is hashed in the DB then you need to set it with wp_update_user

wp_update_user([
    "ID" => $user_id,
    "user_pass" => $_POST['password'],
]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.