Created
March 22, 2012 19:02
-
-
Save coreyweb/2161836 to your computer and use it in GitHub Desktop.
wordpress-user-custom-fields
This file contains 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 custom fields to user profiles | |
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> | |
<th><label for="facebook">Facebook Profile</label></th> | |
<td> | |
<input type="text" name="facebook" id="facebook" value="<?php echo esc_attr( get_the_author_meta( 'facebook', $user->ID ) ); ?>" class="regular-text" /><br /> | |
<span class="description">Please enter a Facebook profile URL.</span> | |
</td> | |
</tr> | |
<tr> | |
<th><label for="twitter">Twitter Username</label></th> | |
<td> | |
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br /> | |
<span class="description">Please enter a Twitter username.</span> | |
</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 'avatar' to the field ID. | |
update_usermeta( $user_id, 'facebook', $_POST['facebook'] ); | |
update_usermeta( $user_id, 'twitter', $_POST['twitter'] ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment