Created
January 31, 2019 10:53
-
-
Save ridhamdholakia/22bbd81ea3941cb0f5c73fdfdea41182 to your computer and use it in GitHub Desktop.
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
/*========= Extra Field Function ======== */ | |
function extra_profile_fields( $user ) { | |
$user_meta = get_userdata($user->ID); | |
$user_roles = $user_meta->roles; | |
$role = $user_roles[0]; | |
$contactnumber = get_the_author_meta( 'contactnumber', $user->ID ); | |
$city = get_the_author_meta( 'city', $user->ID ); | |
$pincode = get_the_author_meta( 'pincode', $user->ID ); | |
$state = get_the_author_meta( 'state', $user->ID ); | |
$country = get_the_author_meta( 'country', $user->ID ); | |
?> | |
<h3>Profile Information</h3> | |
<table class="form-table fh-profile-upload-options"> | |
<tr> | |
<th><label for="twitter">Contact Number<span class="description">(required)</span></label></th> | |
<td> | |
<input type="phone" name="contact" id="contact" class="regular-text" value="<?php echo $contactnumber; ?>"><br/> | |
<span class="description">Please Enter Contact Number.</span> | |
</td> | |
</tr> | |
<tr> | |
<th><label for="twitter">City<span class="description">(required)</span></label></th> | |
<td> | |
<input type="text" name="city" class="regular-text" id="city" value="<?php echo $city; ?>" required/><br/> | |
<span class="description">Please Enter Your City.</span> | |
</td> | |
</tr> | |
<tr> | |
<th><label for="twitter">Pin Code<span class="description">(required)</span></label></th> | |
<td> | |
<input type="text" name="pin" class="regular-text" id="pin" value="<?php echo $pincode; ?>" required/><br/> | |
<span class="description">Please Enter Your PinCode.</span> | |
</td> | |
</tr> | |
<tr> | |
<th><label for="twitter">State/Province<span class="description">(required)</span></label></th> | |
<td> | |
<input type="text" name="state" class="regular-text" id="state" value="<?php echo $state; ?>" required/><br/> | |
<span class="description">Please Enter Your State/Province.</span> | |
</td> | |
</tr> | |
<tr> | |
<th><label for="twitter">Country<span class="description">(required)</span></label></th> | |
<td> | |
<input type="text" name="country" class="regular-text" id="country" value="<?php echo $country; ?>" required/><br/> | |
<span class="description">Please Enter Your Country.</span> | |
</td> | |
</tr> | |
</table> | |
<?php | |
} | |
add_action( 'show_user_profile', 'extra_profile_fields' ); | |
add_action( 'edit_user_profile', 'extra_profile_fields' ); | |
add_action( "user_new_form", "extra_profile_fields" ); | |
/*========= Extra Field Update all Fields Function ======== */ | |
function profile_update($user_id){ | |
$user_meta = get_userdata($user_id); | |
$user_roles = $user_meta->roles; | |
$role = $user_roles[0]; | |
update_usermeta( $user_id, 'contactnumber', $_POST['contact'] ); | |
update_usermeta( $user_id, 'city', $_POST['city'] ); | |
update_usermeta( $user_id, 'pincode', $_POST['pin'] ); | |
update_usermeta( $user_id, 'state', $_POST['state'] ); | |
update_usermeta( $user_id, 'country', $_POST['country'] ); | |
} | |
add_action('profile_update', 'profile_update'); | |
add_action('user_register', 'profile_update'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment