Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created December 20, 2011 23:52
Show Gist options
  • Save mikejolley/1503854 to your computer and use it in GitHub Desktop.
Save mikejolley/1503854 to your computer and use it in GitHub Desktop.
Extra Profile Fields - simple code to add extra user meta fields to the back-end, place in functions.php
add_action( 'show_user_profile', 'show_extra_profile_fields', 10 );
add_action( 'edit_user_profile', 'show_extra_profile_fields', 10 );
function show_extra_profile_fields( $user ) { ?>
<h3><?php _e('Extra Profile Information'); ?></h3>
<table class="form-table">
<tr>
<th><label for="twitter"><?php _e('Twitter'); ?></label></th>
<td>
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_user_meta( $user->ID, 'twitter', true ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e('Please enter your Twitter account name.'); ?></span>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );
function save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) return false;
update_user_meta( $user_id, 'twitter', trim(esc_attr( $_POST['twitter'] )) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment