I found this great article (right here) about creating and saving custom fields for user profiles. The problem is that it only saves text fields. I can't save checkboxes, radio, or any other field types.
Here is the code I am using in the functions.php of my theme:
<?php
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<td>
<input type="text" name="test" id="test" value="<?php echo esc_attr( get_the_author_meta( 'test', $user->ID ) ); ?>" class="regular-text" /><br />
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="test2" id="test2" value="<?php echo esc_attr( get_the_author_meta( 'test2', $user->ID ) ); ?>" class="regular-text" /><br />
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
update_usermeta( $user_id, 'test', $_POST['test'] );
update_usermeta( $user_id, 'test2', $_POST['test2'] );
}
?>
In this sample, the "test" field saves, but the "test2" field doesn't.
Does anyone know how to save different field types (checkboxes, radio, dropdown, etc.) using this code?
Thanks a lot!