I trying to add a custom field to WP Multisite registration. I found hooks to display my field but I can’t save its value to user profile, because to do that I need user ID, but user ID, as I assumed does’t exist before user will confirm registration by link in email. I tryed this code:
add_action( 'wpmu_new_user', 'phone_register_extra_fields' );
function phone_register_extra_fields ( $user_id, $password = "", $meta = array() ) {
$phone_number = filter_var($_POST['phone_number'], FILTER_SANITIZE_NUMBER_INT);
update_user_meta( $user_id, 'phone_number', $phone_number );
}
How can I save the field value to pending user profile that doesn’t have the ID yet? The function update_user_meta() above, doesn't work, because it need user ID.
I fount out, that it is possible to reach user ID on this hook (after activation blog and user in thru email link):
add_action( 'wpmu_activate_blog', 'mu_add_phone_after_activation', 10, 3 );
function mu_add_phone_after_activation( $blog_id, $user_id, $password, $signup_title, $meta ) {
$user_phone = 'TESTnumber';
// $user_phone = $meta['user_phone']; // How to put data in the $meta['user_phone']? On which hook to take it from a $_POST['user_phone'] ?
update_user_meta( $user_id, 'phone_number', $user_phone );
}
But I need to store the phone number from Multisite User and Blog registration page form. Probably it is possible to store it in the $meta variable, but I tried a lot of hooks and didn’t succeed. May be did it wrong. These are the ways I tried:
add_filter( 'signup_user_meta', 'mu_add_phone_in_signup', 10, 4 );
function mu_add_phone_in_signup( $meta, $domain, $path, $title, $user, $user_email, $key ) {
$meta['phone_number'] = '1111111';
return $meta;
}
add_filter( 'add_signup_meta', 'mu_add_phone_in_signup2', 10, 4 );
function mu_add_phone_in_signup2( $meta_defaults = array() ) {
$meta_defaults = array( 'phone_number' => '11111111' );
return $meta_defaults;
}
add_filter( 'signup_site_meta', 'mu_add_phone_in_signup3', 10, 4 );
function mu_add_phone_in_signup3( $domain, $path, $title, $user, $user_email, $key, $meta ) {
$meta['phone_number'] = '11111111';
return $meta;
}
I don't have very experience, so I am going crazy, can't do that 3 days. Will appreciate any halp :) Thank you!