My WP registration form only had username, email address and password.
add_action ('register_form', 'myplugin_register_form'); function myplugin_register_form () {
$first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';
?>
<?php
}
add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
if ( empty( $_POST['first_name'] ) || ! empty( $_POST['first_name'] ) && trim( $_POST['first_name'] ) == '' ) {
$errors->add( 'first_name_error', __( '<strong>ERROR</strong>: You must include a first name.', 'mydomain' ) );
}
return $errors;
}
add_action( 'user_register', 'myplugin_user_register' );
function myplugin_user_register( $user_id ) {
if ( ! empty( $_POST['first_name'] ) ) {
update_user_meta( $user_id, 'first_name', trim( $_POST['first_name'] ) );
}
}
In my registration form (template) I posted the following:
<label><?php _e('First Name', APP_TD) ?></label>
<input tabindex="3" type="text" name="first_name" class="text regular-text" id="display_name" value="<?php echo esc_attr( wp_unslash( $first_name ) ); ?>" maxlength="100" />
And it works as it should. It captures the first name and puts it in the user profile. However, Iβm not sure how to add the last name to it, Iβm pretty new, and for some reason I canβt get the surname to work. Help would be greatly appreciated.
Lloyd source
share