Last active
September 20, 2024 16:30
-
-
Save champsupertramp/c1f6d83406e9e0425e9e98aaa36fed7d to your computer and use it in GitHub Desktop.
Ultimate Member - adding custom fields in account page and tab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Add fields to account page */ | |
add_action('um_after_account_general', 'showExtraFields', 100); | |
function showExtraFields() | |
{ | |
$custom_fields = [ | |
"alternate_email" => "Permanent E-mail Address", | |
"major" => "Major", | |
"minor" => "Minor", | |
"gpa" => "GPA", | |
"graduation_year" => "Graduation Year", | |
"graduation_season" => "Graduation Season", | |
"gpa" => "GPA", | |
"phone_number" => "Phone Number (XXX-XXX-XXXX)", | |
"address_1" => "Permanent Address 1", | |
"address_2" => "Permanent Address 2", | |
"city" => "City", | |
"state" => "State", | |
"zip_code" => "Zip Code" | |
]; | |
foreach ($custom_fields as $key => $value) { | |
$fields[ $key ] = array( | |
'title' => $value, | |
'metakey' => $key, | |
'type' => 'select', | |
'label' => $value, | |
); | |
apply_filters('um_account_secure_fields', $fields, 'general' ); | |
$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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was the only thing that worked perfectly for me.
To show custom fields in the general tab of the accounts screen and to show the input and save correctly.
Thank you!