I am creating a new User with wp_insert_user() function in an AJAX call. After that I need to add the phone number as custom field, so I need to use the wordpress hook user_register and I don’t know how to use it.
add_action('wp_ajax_nopriv_register', 'register_user');
add_action('wp_ajax_register', 'register_user');
function registrar_cliente(){
if(isset($_POST['dataForPHP'])){
$phone = wp_filter_nohtml_kses($_POST['dataForPHP'][0]);
$name = wp_filter_nohtml_kses($_POST['dataForPHP'][1]);
$email = wp_filter_nohtml_kses($_POST['dataForPHP'][2]);
$userdata = [//adding data];
$user_id = wp_insert_user($userdata);
}
}
How can I use now do_action( 'user_register', int $user_id, array $userdata )
in order to insert $phone to the user in a custom field?
2
Answers
You can store the value of the custom field in user_meta.
Code for adding extra fields in Edit User Section:
Code for saving extra fields details in the database from the edit screen(If you want to change value from edit screen):
You can use this code to register and enter the user.