WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on a custom sign up proces where a user first fills in his name and email, then receives an activation e-mail and then the sign up proces continues.

The e-mail contains an activation link with a reference. I need to save this reference in my new user so if the user clicks on the link I can retrieve back the user data.

But for some reason I cannot add my user meta data by inserting the new user.

So first I have my form handling where I get the POST values. And If they are true I start this code:

$ref = md5( get_bloginfo( 'name' ) . $reg_email );
$activation_url = get_bloginfo( 'wpurl' ) . '/search-company?ref=' . $ref;

// Create user
$random_password = wp_generate_password( 12, true, false );
$user_id = username_exists( $email );
$userdata = array(
  'user_login'  => $email,
  'user_pass'   => $random_password,
  'user_email'  => $email,
  'first_name'  => $first_name,
  'last_name'   => $surname,
  'role'            => 'author',
wp_insert_user( $userdata );
add_user_meta( $userdata, 'verification_ref', $ref );

And then I send my e-mail by wp_mail() with the activation link, this works fine, but I only need to save the verification reference in the user meta of the user.

share|improve this question
up vote 3 down vote accepted

wp_insert_user returns your new user's ID, if created successful. You can add the user_meta to this ID:

$userid = wp_insert_user( $userdata );
if ( !is_wp_error( $userid ) ) { // check if insert was successful
    add_user_meta( $userid, 'verification_ref', $ref ); // add the meta
} else {
    /* Error Handling */
share|improve this answer
Thanks Again! You are the best! – Robbert Feb 21 '14 at 13:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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