I use these two functions to be able to set the first and last name when I go to Add New User:
// Add First and Last name to Add New User
function add_new_user_name_fields($user) {
?>
<table class="form-table">
<tr>
<th><label for="first_name">First Name</label></th>
<td>
<input type="text" class="regular-text" name="first_name" id="first_name" />
</td>
</tr>
<tr>
<th><label for="last_name">Last Name</label></th>
<td>
<input type="text" class="regular-text" name="last_name" id="last_name" />
</td>
</tr>
</table>
<?php
}
add_action( "user_new_form", "add_new_user_name_fields" );
// Save First and Last name when new user is added
function save_add_new_user_name_fields($user_id) {
if (!current_user_can('create_users'))
return false;
update_user_meta($user_id, 'first_name', $_POST['first_name']);
update_user_meta($user_id, 'last_name', $_POST['last_name']);
}
add_action('user_register', 'save_add_new_user_name_fields');
This works very good, but how do I set both these fields to be required? Right now I am able to add a new user without setting anything in these fields.
Lastly, adding these two fields means that they end up on the bottom below Add the user without sending an email that requires their confirmation.
Is it possible to place these two fields directly below the Username
?
Thanks!