How To Add Fields In WordPress Admin Add User

Many developers want to add the fields in admin panel Add User but there is now directly hook to got this functionality. In wordpress i have searched and find one hook which are able to add fields in wordpress admin add use. Hook is “user_new_form” provide you the ability to add fields in add user. below the code analysis.

//call the hook and define function in functions.php


//define function fields

function new_form_fields_alk()
<table class="form-table">
<th><label for="twitter">Contact Number</label></th>
<td><input id="contact_number" class="regular-text" name="contact_number" type="text" value="< echo esc_attr( get_the_author_meta( 'contact_number', $user->ID ) ); >" /></td>
</tr >
<tr >
<th ><label for="twitter"> Address</label></th>
<td> <input id="address" class="regular-text" name="address" type="text" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" /></td>

//After that look admn add user there is fields are showing. //Now need to write code for save the fields data define //function and call save hooks. function save_custom_user_profile_fields($user_id){
# again do this only if you can if(!current_user_can('manage_options'))
return false; # save my custom field update_usermeta($user_id, 'contact_number', $_POST['contact_number']); update_usermeta($user_id, 'address', $_POST['address']); } add_action('user_register', 'save_custom_user_profile_fields');

Done at fields are saved when admin add user.You also need to write code for showing this field in edit user. Thank you reading wait for next post 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *