1

Updating some meta fields on registration and providing the user the option to pick a password yet the registration email sends the auto generated password. User defined password works and not emailed pass.

add_action( 'user_register', 'jwh_register_extra_fields', 100 );
function jwh_register_extra_fields( $user_id, $password = '', $meta = array() )  {
$userdata = array();

$userdata['ID'] = $user_id;
if ( $_POST['password'] !== '' ) {
    $userdata['user_pass'] = $_POST['password'];
}

$userdata['first_name'] = $_POST['first_name'];
$userdata['last_name'] = $_POST['last_name'];
$userdata['user_url'] = $_POST['user_url'];

$new_user_id = wp_update_user( $userdata );
}
7
  • Mate you need to clerify you question. Are you talking about registration with custom password or changing password after user is already registered.
    – Sagive
    Commented May 2, 2013 at 20:48
  • Yep. Registration works and custom password is stored but the welcome email from WordPress sends the auto generated pass. Commented May 2, 2013 at 20:52
  • but this function updated user information and is not used for registration... is this the function you are trying to use to register new user or just to update the user infromation???
    – Sagive
    Commented May 2, 2013 at 20:59
  • Ahh. Ok. to it fires AFTER registration. How do I hook in earlier during registration? Commented May 2, 2013 at 21:16
  • sorry to open a mini chat here - i just dont get where you get the $user_id value from? if it a new user registration there is no user id yet... (i just dont want to misslead you with the wrong answer) - Should i just dissregard your function and give you a way to register a new member to your site?
    – Sagive
    Commented May 2, 2013 at 21:22

1 Answer 1

2

Welcome to WPSE. You can use wp_insert_user, you don't need to hook onto anything.

Assuming here they fill out a form with a name, username, email and password field, and you capture it however you want.

$name_array = explode(' ',$_POST['name']);
$user = array(
    'user_login' => $_POST['username'],
    'user_pass' => $_POST['password'],
    'user_email' => $_POST['email'],
    'first_name' => $name_array[0],
    'last_name' => $name_array[1],
            );
$user_id = wp_insert_user( $user );

wp_new_user_notification( $user_id, $_POST['password'] );
6
  • I still get the auto generated pass. Commented May 2, 2013 at 21:51
  • I just ran it again, i got my entered password, are you sure you're passing the second parameter to wp_new_user_notification? And you're using your own form right, not the stand wp registration form? Commented May 2, 2013 at 22:20
  • Oops. Typo in form action. This works, but it's nice having WP do all the checking wether a username exists and other validation. Commented May 3, 2013 at 1:11
  • So would you consider this code safe? How do you know that POST data is safe(and set) prior to the user insertion?
    – t31os
    Commented May 3, 2013 at 9:35
  • No, I don't consider it safe. @t31os I'd really love your input on this question: meta.wordpress.stackexchange.com/questions/2472/… Commented May 3, 2013 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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