Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethiel88/72843343a7816f77ba033addf96457ee to your computer and use it in GitHub Desktop.
Save ethiel88/72843343a7816f77ba033addf96457ee to your computer and use it in GitHub Desktop.
Ultimate Member - adding custom fields in account page, edit and save working ok!
add_action('um_after_account_general', 'showExtraFields', 100);
function showExtraFields()
{
$custom_fields = [
"razon_social" => "Razón Social",
"nit" => "NIT",
"ci" => "CI",
"phone_number" => "Número de teléfono fijo",
"mobile_number" => "Número de teléfono móvil",
];
foreach ($custom_fields as $key => $value) {
$fields[ $key ] = array(
'title' => $value,
'metakey' => $key,
'type' => 'select',
'label' => $value,
);
$field_value = get_user_meta(um_user('ID'), $key, true) ? : '';
$html = '<div class="um-field um-field-'.$key.'" data-key="'.$key.'">
<div class="um-field-label">
<label for="'.$key.'">'.$value.'</label>
<div class="um-clear"></div>
</div>
<div class="um-field-area">
<input class="um-form-field valid "
type="text" name="'.$key.'"
id="'.$key.'" value="'.$field_value.'"
placeholder=""
data-validate="" data-key="'.$key.'">
</div>
</div>';
echo $html;
}
apply_filters('um_account_secure_fields', $fields, get_current_user_id());
}
@twittwoo
Copy link

twittwoo commented Jan 9, 2020

Hey there, I'm still getting the issue with it not saving custom fields. Could this be something to do with using ACF?

@alexliptsin
Copy link

Nice :) Dummy question. Where do you paste it?

@aldoyh
Copy link

aldoyh commented Feb 26, 2021

Nice :) Dummy question. Where do you paste it?

At the end of functions.php of your theme.

Question: How do I display that custom field as a column from the WP Admin -> List Users?

@ayoubkhan58
Copy link

ayoubkhan58 commented Feb 23, 2022

@aldoyh
Copy link

aldoyh commented Feb 23, 2022

Probably outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment