Last active
December 16, 2017 10:47
-
-
Save makbeta/5851535 to your computer and use it in GitHub Desktop.
WordPress: Adding custom user/profile fields manually
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
function my_show_extra_profile_fields( $user ) { ?> | |
<div class="subscription-info"> | |
<h3>Subscription Information</h3> | |
<table class="form-table"> | |
<tr> | |
<th><label for="subscription">Customer ID</label></th> | |
<td> | |
<input type="text" name="subscription" id="subscription" value="<?php echo esc_attr( get_user_meta( $user->ID, 'subscription', 1) ); ?>" class="regular-text" /><br /> | |
<span class="description">Please enter your customer ID.</span> | |
</td> | |
</tr> | |
</table> | |
</div> | |
<?php } | |
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 'subscription' to the field ID. */ | |
update_user_meta( $user_id, 'subscription', $_POST['subscription'] ); | |
} | |
// custom profile fields | |
add_action( 'show_user_profile', 'my_show_extra_profile_fields', 5 ); | |
add_action( 'edit_user_profile', 'my_show_extra_profile_fields', 5 ); | |
add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); | |
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment