Created
July 4, 2017 08:45
-
-
Save qwersk/5eeb644a57677d2a3b6fd4a926c959fc to your computer and use it in GitHub Desktop.
ADD CUSTOM FIELD TO USER PROFILE #WP #WORDPRESS
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_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="phone">Phone Number</label></th> | |
<td> | |
<input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" /><br /> | |
<span class="description">Please enter your phone number.</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; | |
update_usermeta( $user_id, 'phone', $_POST['phone'] ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment