Created
November 19, 2015 17:38
-
-
Save bappi-d-great/41fbf34da477e159e852 to your computer and use it in GitHub Desktop.
How to add extra field in the wordpress user profile
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
<?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