How to add new fields to the “Add New User” screen in the wordpress admin panel?
I want to add a new field “Organization Name” to the add new user screen in wordpress backend.
add custom fields to user profile wordpress without plugin | add user meta on registration wordpress | wordpress add more fields to user registration | wordpress display user meta fields in admin | wordpress user registration plugin with custom fields | how to add custom field in wordpress post admin | add custom column to users admin panel
add custom fields to user profile wordpress without plugin | add user meta on registration wordpress | wordpress add more fields to user registration | wordpress display user meta fields in admin | wordpress user registration plugin with custom fields | how to add custom field in wordpress post admin | add custom column to users admin panel
add custom fields to user profile wordpress without plugin | add user meta on registration wordpress | wordpress add more fields to user registration | wordpress display user meta fields in admin | wordpress user registration plugin with custom fields | how to add custom field in wordpress post admin | add custom column to users admin panel
add custom fields to user profile wordpress without plugin | add user meta on registration wordpress | wordpress add more fields to user registration | wordpress display user meta fields in admin | wordpress user registration plugin with custom fields | how to add custom field in wordpress post admin | add custom column to users admin panel
add custom fields to user profile wordpress without plugin | add user meta on registration wordpress | wordpress add more fields to user registration | wordpress display user meta fields in admin | wordpress user registration plugin with custom fields | how to add custom field in wordpress post admin | add custom column to users admin panel
add custom fields to user profile wordpress without plugin | add user meta on registration wordpress | wordpress add more fields to user registration | wordpress display user meta fields in admin | wordpress user registration plugin with custom fields | how to add custom field in wordpress post admin | add custom column to users admin panel add custom fields to user profile wordpress without plugin add user meta on registration wordpress wordpress add more fields to user registration wordpress display user meta fields in admin wordpress user registration plugin with custom fields how to add custom field in wordpress post admin add custom column to users admin panel
Share
I am using Arcane theme and I added organizations as post type. Also “vg_organization_id” was a user meta.
Please add the below code in functions.php file to get the extra field in user profile page.
function custom_user_profile_fields($user){
if(isset($_GET['user_id']) && $_GET['user_id'] != ""){
$user_id = $_GET['user_id'];
}else{
$user_id = "";
}
$organization = arcane_user_is_in_organization($user_id);
if($organization){
$get_org_data = get_post($organization);
$org_id = $get_org_data->ID;
}else{
$org_id = "";
}
if(is_object($user))
$orgs = arcane_get_organizations();
else
$orgs = arcane_get_organizations();
?>
<table class="form-table">
<tbody>
<tr class="form-field">
<th scope="row"><label for="vg-orgs">Select Organization</label></th>
<td>
<select name="vg_organization_id" id="vg_organization_id" >
<option value="">Select a organization</option>
<?php if($orgs !== false){ ?>
<?php foreach($orgs as $val){ ?>
<option value="<?php echo $val->ID; ?>" <?php if($org_id != "" && $org_id == $val->ID){echo "selected";} ?>><?php echo $val->post_title; ?></option>
<?php } ?>
<?php } ?>
</select>
</td>
</tr>
</tbody>
</table>
<?php
}
add_action( 'show_user_profile', 'custom_user_profile_fields' );
add_action( 'edit_user_profile', 'custom_user_profile_fields', 30);
add_action( "user_new_form", "custom_user_profile_fields");
add_action('edit_user_profile_update', 'update_extra_profile_fields');
function update_extra_profile_fields($user_id) {
if (isset($_REQUEST['vg_organization_id']) && $user_id != "") {
$org_id = $_REQUEST['vg_organization_id'];
update_user_meta($user_id, 'vg_organization_id', $org_id);
}
}
add_action('user_register','add_extra_profile_fields');
function add_extra_profile_fields($user_id){
if (isset($_REQUEST['vg_organization_id']) && $user_id != "") {
$org_id = $_REQUEST['vg_organization_id'];
add_user_meta($user_id, 'vg_organization_id', $org_id);
}
}