Hello again,
After writing that, I decided to just do the research and put together some code to do what you’re looking for.
Here is is:
function shea_user_profile_dateofbirth( $user ) {
?>
<h2><?php _e( 'Extra Information' ); ?></h2>
<table class="form-table">
<tr>
<th><label for="dateofbirth"><?php _e( 'Date of Birth' ); ?></label></th>
<td>
<input type="date" id="dateofbirth" name="dateofbirth" value="<?php
echo esc_attr( get_the_author_meta( 'dateofbirth', $user->ID ) ); ?>">
</td>
</tr>
</table>
<?php
}
add_action( 'show_user_profile', 'shea_user_profile_dateofbirth' );
add_action( 'edit_user_profile', 'shea_user_profile_dateofbirth' );
function shea_enqueue_date_picker() {
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_style( 'jquery-ui-datepicker' );
?>
<script>
jQuery(document).ready(function() {
jQuery('#dateofbirth').datepicker();
});
</script>
<?php
}
add_action( 'admin_enqueue_scripts', 'shea_enqueue_date_picker' );
function shea_save_user_dateofbirth( $user_id ) {
if ( current_user_can( 'edit_user', $user_id ) ) {
update_user_meta( $user_id, 'dateofbirth', $_POST['dateofbirth'] );
}
}
add_action( 'personal_options_update', 'shea_save_user_dateofbirth' );
add_action( 'edit_user_profile_update', 'shea_save_user_dateofbirth' );
Unfortunately, it’s not possible to insert a new field into any existing section aside from ‘Personal Options’, so I’ve had to add it in a new section near the bottom.