//Pincode starts here.
add_action( 'show_user_profile', 'show_extra_profile_fields' );
add_action( 'edit_user_profile', 'show_extra_profile_fields' );
function show_extra_profile_fields( $user ) {
if(is_user_logged_in() ) {
$user = wp_get_current_user();
$user->roles[0];
if ($user->roles[0] == 'administrator') { ?>
<table class="form-table">
<tr>
<th><label for="contact">Pincode Assigned</label></th>
<td>
<textarea name="stokist_pincode_allocated" id="stokist_pincode_allocated" class="regular-text"><?php echo esc_attr( get_the_author_meta( 'stokist_pincode_allocated', $user->ID ) ); ?></textarea><br />
<span class="description">Please enter your Pincode.</span>
</td>
</tr>
</table>
<?php } } }
add_action( 'personal_options_update', 'save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_profile_fields' );
function save_extra_profile_fields( $user_id ) {
if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_usermeta( $user_id, 'stokist_pincode_allocated', esc_attr( $_POST['stokist_pincode_allocated'] ) );
}
Tuesday, 2 May 2023
Show extra field in profile
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment