Created
December 20, 2011 23:52
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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