Skip to content

Instantly share code, notes, and snippets.

@bappi-d-great
Created November 19, 2015 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bappi-d-great/41fbf34da477e159e852 to your computer and use it in GitHub Desktop.
Save bappi-d-great/41fbf34da477e159e852 to your computer and use it in GitHub Desktop.
How to add extra field in the wordpress user profile
<?php
add_action( 'show_user_profile', 'extra_fields' );
add_action( 'edit_user_profile', 'extra_fields' );
add_action( 'personal_options_update', 'save_fields' );
add_action( 'edit_user_profile_update', 'save_fields' );
function extra_fields($user) {
?>
<h3><?php _e("Extra profile information", "DOMAIN"); /*DOMAIN = Lang domain for l10n (optional)*/ ?></h3>
<table class="form-table">
<tbody>
<tr>
<th><?php _e("Extra profile information", "DOMAIN"); /*DOMAIN = Lang domain for l10n (optional)*/ ?></th>
<td><input class="regular-text" id="facebook" type="text" name="facebook" value="<?php echo esc_attr( get_the_author_meta( 'facebook', $user->ID ) ); ?>" /></td>
</tr>
</tbody>
</table>
<?php }
function save_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; } //Checking if the current user has ability to edit the user profile information
update_user_meta( $user_id, 'facebook', $_POST['facebook'] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment