User Meta – Additional Profile Fields – Not showing on Add New User – WordPress

  php, wordpress

I am adding a couple of additional User Profile fields in WordPress user profiles. Everything seems to be working pretty well for view, edit and update, except the fields are not showing up on ‘Add New’ user profile creation.

I’ve got the user_register action there add_action('user_register', 'tbc_save_extra_profile_fields', 10, 1);

Also tried with add_action('user_register', 'tbc_show_extra_profile_fields', 10, 1);

But the fields are still not coming up for New accounts.

What am I doing wrong?

Here is my complete code:

function tbc_custom_define() {
  $custom_meta_fields = array();
  $custom_meta_fields['tbc_company_name'] = 'Company name';
  $custom_meta_fields['tbc_company_website'] = 'Company website';
  return $custom_meta_fields;
}

function tbc_show_extra_profile_fields($user) {
  print('<h3>Business information</h3>');

  print('<table class="form-table">');

  $meta_number = 0;
  $custom_meta_fields = tbc_custom_define();
  foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
    $meta_number++;
    print('<tr>');
    print('<th><label for="' . $meta_field_name . '">' . $meta_disp_name . '</label></th>');
    print('<td>');
    print('<input type="text" name="' . $meta_field_name . '" id="' . $meta_field_name . '" value="' . esc_attr( get_the_author_meta($meta_field_name, $user->ID ) ) . '" class="regular-text" /><br />');
    print('<span class="description"></span>');
    print('</td>');
    print('</tr>');
  }
  print('</table>');
}

function tbc_save_extra_profile_fields($user_id) {

  if (!current_user_can('edit_user', $user_id))
    return false;

  $meta_number = 0;
  $custom_meta_fields = cdl_custom_define();
  foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
    $meta_number++;
    update_user_meta( $user_id, $meta_field_name, $_POST[$meta_field_name] );
  }
}
add_action('show_user_profile', 'tbc_show_extra_profile_fields');
add_action('edit_user_profile', 'tbc_show_extra_profile_fields');
add_action('personal_options_update', 'tbc_save_extra_profile_fields');
add_action('edit_user_profile_update', 'tbc_save_extra_profile_fields');
add_action('user_register', 'tbc_save_extra_profile_fields', 10, 1);

Source: Ask PHP

LEAVE A COMMENT