By default, it is not possible to save extra fields other than username/email/password, but you can achieve this with the wp_rest_user_user_register
hook:
/** Custom extra fields on user registration. */
add_filter( 'rest_pre_dispatch', 'rest_store_request', 10, 3 );
add_action( 'wp_rest_user_user_register', 'save_custom_user_fields' );
/** Save HTTP parameters in a global var, to be used later on "save_custom_user_fields". */
function rest_store_request( $result, $server, $request ) {
global $rest_request;
$rest_request = $request;
return $result;
}
/** Called on register user - add extra custom fields. */
function save_custom_user_fields( $user ) {
/** Get inputs from POST. */
global $rest_request;
$parameters = $rest_request->get_json_params();
/** Sanitization. */
$first_name = sanitize_text_field( $parameters['first_name'] );
$last_name = sanitize_text_field( $parameters['last_name'] );
/** Add meta records. */
add_user_meta( $user->ID, 'first_name', $first_name, true );
add_user_meta( $user->ID, 'last_name', $last_name, true );
/** Update user record. */
$user->first_name = $first_name;
$user->last_name = $last_name;
wp_update_user( $user );
/** "New user registration" email to admin: uncomment to enable it. */
// wp_send_new_user_notifications( $user->ID, 'user' );
}
You can paste this code to your functions.php
.