-
-
Save champsupertramp/c1f6d83406e9e0425e9e98aaa36fed7d to your computer and use it in GitHub Desktop.
<?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; | |
} | |
} |
So, is there a working code so we can save to custom fields?
Hi Everyone,
I'll be posting a new tutorial on my website. I'll share how you can add UM Profile Form to the UM Account form in a separated tab. I'll provide custom codes to add multiple tabs with easy steps. Subscribe to my newsletter on my website: www.champ.ninja
Dummy question. Where do you paste it?
In the functions.php file.
So, is there a working code so we can save to custom fields?
Yes - the code is in the getUMFormData function.
In the functions.php file.
Thanks
HI! many people that say they have solved when in fact in my opinion none of the answers or solutions achieve the purpose of the title "adding custom fields".
What is really trying to achieve (and I think that is the purpose of this code) adding a custom field "NEW" instead of reusing a previously created one.
I think many who claim to have been successful with some proposals used fields previously created either pre-established from UM or created by oneself with the illusion of having succeeded. I need someone to clarify.
And I suppose (I hope not mistakenly) that they create them in the visual interface of the "field manager" and then re-use those fields in the code.
I see many examples that talking about fields like: "phone_number", "mobile_number", "job", "company" and I do not see any with an example that says "custom_field_0", "custom_field_1", "custom_field_2" the idea with the initial code is to create NEW fields "I suppose" and not to reuse those already created.
@radhex or @joanhypeproject are very close to the conjecture I am trying to explain, but try your code without any results.
Then I see extracts of code like this that confuse me:
$ names = array ("phone_number", "church_name", "company", "tax-number", "sector", "company-employee-count", "company-address");
Where is the structure of each of these fields of the type:
$ fields [$ key] = array ( 'title' => $ value, 'metakey' => $ key, 'type' => 'select', 'label' => $ value, );
Which is what indicates that we are creating new and not pre-existing fields? or maybe even something like this:
$ fields ['custom_field_0'] = Array ("type" => "select", "title" => "custom_field_0", "metakey" => "custom_field_0", "options" => Array ( "0" => "Custom 1", "1" => "Custom 2", "2" => "Custom 3"), "visibility" => "all", "label" => "Custom Field", "placeholder" => "Custom Field", "public" => 1, "editable" => 1);
Apparently UM has a some kind of restriction for that purpose because nobody has found the solution to the problem.
With the first code of @champsupertramp in fact the fields are displayed on the screen but they can not be stored.
Has anyone been able to "REALLY STORE NEW CUSTOM FIELDS" that can be seen after clicking the "Update" button?
Thanks!
Agree. Did you find solution?
@alexlipstin Maybe this is what you want. Created a new field called - ID number.
`add_action('um_after_account_general', 'after_account_general_custom_fields', 100);
function after_account_general_custom_fields()
{
$custom_fields = [
'user_id_number' => [
'title' => 'ID Number',
'label' => 'ID Number',
'metakey' => 'user_id_number',
'type' => 'text',
'options' => ['Update'],
'required' => 1,
'public' => 1,
'editable' => 1,
],
];
$fields = apply_filters('um_account_secure_fields', $custom_fields, um_user('ID'));
UM()->builtin()->saved_fields = $fields;
UM()->builtin()->set_custom_fields();
$output = '';
foreach ($fields as $key => $data) {
$output .= UM()->fields()->edit_field($key, $data);
}
echo $output;
}
/*
add_action( 'um_account_pre_update_profile', 'my_account_pre_update_profile', 10, 2 );
function my_account_pre_update_profile( $changes, $user_id ) {
// your code here
}
*/
add_action('um_account_pre_update_profile', 'getUMFormData', 10, 2);
function getUMFormData($changes, $user_id){
// $id = um_user('ID');
$names = array('user_id_number');
foreach( $names as $name )
update_user_meta( $user_id, $name, $_POST[$name] );
}`
Has anyone tried using a Profile Form in the Account form in a custom tab? You should be able to use the Profile Form as a custom form in the Account tab. Please see this tutorial:
https://www.champ.ninja/2020/05/add-a-custom-account-tab-with-profile-form-fields/
@champsupertramp Your solution is almost working for me, but the problem I have is that dropdown fields do not save correctly. It only saves the 'value' which is a number, and not what the actual list option title is.
EDIT
This appears to be the way UM is creating the mark-up for the dropdown. A dropdown on the registration page uses the correct mark-up for options <option value="Marketing">Marketing</option>
but when the same field is pulled into another form - a custom profile form in this instance - the mark-up becomes <option value="1">Marketing</option>
so the data saved becomes a bit useless. I noticed in your solution you have a 'fix' for radios, does it need one for dropdowns too?
Using $_POST['fieldname'] in um_account_pre_update_profile seems to work for me. Just don't forget to sanitize it!
Hey guys! Does anyone know how to add placeholders values to the existing account fields like "First name", "Password" etc.?
I want to style the fields by removing the labels and keeping only the placeholders..
@dtipson Could you tell me what exactly I should do to "sanitize" it? I am new to wordpress/coding and encountering the same issue as @haydnjames.
When I do $_POST['fieldname'] it just clears all data and nothing can be saved (even the pre-saved fields clears up).
I have this code from @rkenn on my functions.php which works almost perfectly, except for my issue above.
add_action('um_after_account_general', 'showUMExtraFields', 100);
function showUMExtraFields() {
$id = um_user('ID');
$output = '';
$names = array('phone_number', 'company');
$fields = array();
foreach( $names as $name )
$fields[ $name ] = UM()->builtin()->get_specific_field( $name );
$fields = apply_filters('um_account_secure_fields', $fields, $id);
foreach( $fields as $key => $data )
$output .= UM()->fields()->edit_field( $key, $data );
echo $output;
}
add_action('um_account_pre_update_profile', 'getUMFormData', 100);
function getUMFormData(){
$id = um_user('ID');
$names = array('phone_number', 'company');
foreach( $names as $name )
update_user_meta( $id, $name, $_POST[$name] );
}
Hello world there is a solution to view and save the custom field in ultimate member account profile .
//hook to display input field
add_action('um_after_account_general', 'showExtraFields', 100);
function showExtraFields()
{
//these are the meta fields created in registration field
$custom_fields = [
"Facility_name" => "Facility name",
"license" => "license",
"total_beds" => "Total no of beds",
];
foreach ($custom_fields as $key => $value) {
$fields[ $key ] = array(
'title' => $value,
'metakey' => $key,
'type' => 'select',
'label' => $value,
);
apply_filters('um_account_secure_fields', $fields, 'wall_privacy' );
$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;
}
}
//action to update values of custom field
add_action( 'um_account_pre_update_profile', 'my_account_pre_update_profile', 10, 2 );
function my_account_pre_update_profile( $changes, $user_id ) {
update_user_meta( $user_id, 'Facility_name', $_POST['Facility_name'] );
update_user_meta( $user_id, 'license', $_POST['license'] );
update_user_meta( $user_id, 'total_beds', $_POST['total_beds'] );
}
use the above code to save custom field in ultimate member account page .
Thank me later !!!..
Hi,
After many attempts, i've find out one code that worked for me:
/* create new tab */
add_filter('um_account_page_default_tabs_hook', 'MyCustomTab', 100 );
function MyCustomTab( $tabs ) {
$tabs[800]['MyCustomTab']['icon'] = 'um-faicon-pencil-square-o'; // tab icon
$tabs[800]['MyCustomTab']['title'] = 'MY CUSTOM TAB HERE'; // tab title
$tabs[800]['MyCustomTab']['submit_title'] = 'Update'; // button text
$tabs[800]['MyCustomTab']['custom'] = true;
return $tabs;
}
/* make our new tab hookable */
add_action('um_account_tab__MyCustomTab', 'um_account_tab__MyCustomTab');
function um_account_tab__MyCustomTab( $info ) {
global $ultimatemember;
extract( $info );
$output = $ultimatemember->account->get_tab_output('MyCustomTab');
if ( $output ) { echo $output; }
}
/* Finally we add some content in the tab */
add_filter('um_account_content_hook_MyCustomTab', 'um_account_content_hook_MyCustomTab');
function um_account_content_hook_MyCustomTab( $output ){
ob_start();
$id = um_user('ID');
$output = '<div class="um-field">';
$names = array('CUSTOMMETA1','CUSTOMMETA2'); // ADD THE META-KEYS HERE
$fields = array();
foreach( $names as $name ){
$fields[ $name ] = UM()->builtin()->get_specific_field( $name );
}
$fields = apply_filters('um_account_secure_fields', $fields, $id);
foreach( $fields as $key => $data ){
$output .= UM()->fields()->edit_field( $key, $data );
}
$output .= '</div>';
$output .= ob_get_contents();
ob_end_clean();
return $output;
}
/* ensure that the custom fields are updated when the account is updated */
add_action('um_account_pre_update_profile', 'getUMFormData', 100);
function getUMFormData(){
$id = um_user('ID');
$names = array('CUSTOMMETA1','CUSTOMMETA2'); // ADD THE META-KEYS HERE
foreach( $names as $name )
update_user_meta( $id, $name, $_POST[$name] );
}
Just change CUSTOMMETA1 and CUSTOMMETA2
Note that you've got to "create" the meta in the form settings from UM.
Hope it helps !
Source : https://gist.github.com/ultimatemember/f7eab149cb33df735b08#gistcomment-3526342
to view&update custom fields in the [ultimatemember_account] page, this is some distilled code from here, to be added to your theme's functions.php:
add_action('um_after_account_general', 'showUMExtraFields', 100); function showUMExtraFields() { $id = um_user('ID'); $output = ''; $names = array('phone_number', 'company'); $fields = array(); foreach( $names as $name ) $fields[ $name ] = UM()->builtin()->get_specific_field( $name ); $fields = apply_filters('um_account_secure_fields', $fields, $id); foreach( $fields as $key => $data ) $output .= UM()->fields()->edit_field( $key, $data ); echo $output; } add_action('um_account_pre_update_profile', 'getUMFormData', 100); function getUMFormData(){ $id = um_user('ID'); $names = array('phone_number', 'company'); foreach( $names as $name ) update_user_meta( $id, $name, $_POST[$name] ); }
tested with 2.0.13
How would one use this code to display the custom fields after another specific field (such as after the Username field in the Account tab), as well as make the custom fields uneditable? (Similar to the Username field in the account tab)
Hey all
Here is the scenario
Person XYZ register and marks a radio button field I added "usr_isArtist" as Yes and saves his profile
Person ABC browses the profiles and comes across Person XYZ's profile and see he is an artist. Person ABC would like to click on a button on the Profile page of XYZ that will open a WPForms page that contains form to do some inquiry.
I currently added a button on the "Page" where my profile page is displaying the Profile (at the very bottom as I did not know how to add the button as part of the profile "Template / Form")
But coming across this page I think it might be possible to add a button as part of the Profile View page/template/form that states "Inquire about Me" and when the user clicks on this button then the "url" will be containing a query string to be used in the WP Forms page...
The Query string will contain the Artists Name and Surname...
the URL I am playing with is https://bookartist.co.za/booking-inquiry?artist_name={first_name}+{last_name}
so you can view my page: https://bookartist.co.za/user/peterhoven/ with the button at the very bottom, (Not working correctly) and it will take you to the WP Forms page...
Please can you guys assist me.
- I would like the button to be added at the top, possibly JUST next to the "First Name" field
- It must pass the Artist's First and Last name to the WP Forms page...
I thank you in advance
Hi everybody !
anyone know how to hide custom fields registration in mail notification admin when its empty? I used the hook "um_profile_submitted__filter" but it don't work , all custom fields always show.
this is my code:
add_filter("um_profile_submitted__filter","um_profile_submitted", 999, 1 );
function um_profile_submitted( $submitted ){
$fields_mail = array();
foreach (unserialize($submitted) as $key => $item){
if (!empty($item)){
$fields_mail[$key] = $item;
}
}
$submitted = serialize($fields_mail);
return $submitted;
}
thanks in advance
Hi there folks! Ultimate code for custom fields, and succesful saving Front-End / Back-End.
Change parameters "FIELD_01" & "FIELD_02" for yours (you can add asmany as you wish).
Paste it in the end of the functions.php file in your theme.
`/**
- EXTRA ULTIMATE MEMBER
*/
add_action('um_after_account_general', 'showExtraFields', 100);
function showExtraFields()
{
//these are the meta fields created in registration field
$custom_fields = [
"FIELD_01" => "Field 01",
"FIELD_02" => "Field 02",
];
foreach ($custom_fields as $key => $value) {
$fields[ $key ] = array(
'title' => $value,
'metakey' => $key,
'type' => 'select',
'label' => $value,
);
apply_filters('um_account_secure_fields', $fields, 'wall_privacy' );
$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;
}
}
//action to update values of custom field
add_action( 'um_account_pre_update_profile', 'my_account_pre_update_profile', 10, 2 );
function my_account_pre_update_profile( $changes, $user_id ) {
update_user_meta( $user_id, 'FIELD_01', $_POST['FIELD_01'] );
update_user_meta( $user_id, 'FIELD_02', $_POST['FIELD_02'] );
}
/**
- CODE FOR VIEWING "Extra profile information" AREA IN YOUR USERS BACK-END, MATCH IT WITH YOUR CUSTOM NAMES
*/
function mysite_custom_define() {
$custom_meta_fields = array();
$custom_meta_fields['FIELD_01'] = 'Field 01';
$custom_meta_fields['FIELD_02'] = 'Field 02';
return $custom_meta_fields;
}
function mysite_columns($defaults) {
$meta_number = 0;
$custom_meta_fields = mysite_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
$defaults[('mysite-usercolumn-' . $meta_number . '')] = __($meta_disp_name, 'user-column');
}
return $defaults;
}
function mysite_custom_columns($value, $column_name, $id) {
$meta_number = 0;
$custom_meta_fields = mysite_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
if( $column_name == ('mysite-usercolumn-' . $meta_number . '') ) {
return get_the_author_meta($meta_field_name, $id );
}
}
}
function mysite_show_extra_profile_fields($user) {
print('
Extra profile information
');print('');
$meta_number = 0;
$custom_meta_fields = mysite_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
print('');
print('');
print('');
print('');
}
print('
' . $meta_disp_name . ' | '); print(' '); print(''); print(' |
---|
}
function mysite_save_extra_profile_fields($user_id) {
if (!current_user_can('edit_user', $user_id))
return false;
$meta_number = 0;
$custom_meta_fields = mysite_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
update_usermeta( $user_id, $meta_field_name, $_POST[$meta_field_name] );
}
}
add_action('show_user_profile', 'mysite_show_extra_profile_fields');
add_action('edit_user_profile', 'mysite_show_extra_profile_fields');
add_action('personal_options_update', 'mysite_save_extra_profile_fields');
add_action('edit_user_profile_update', 'mysite_save_extra_profile_fields');
add_action('manage_users_custom_column', 'mysite_custom_columns', 15, 3);
add_filter('manage_users_columns', 'mysite_columns', 15, 1);`
That's all, I hope it helps some of you 🌊
Thank you so much for this @ATICOSEGUNDA , it is the only code that worked on the most recent UM version. Do you know if we can also show the custom fields value in another page? I need to show UM custom fields of a custom post author (city, address, etc) in the posts they created for everyone to see.
@ivanoconfa you can and should do that without UM, in my case I use Elementor with queries and is so easy to show post author infos. Good luck!
Thank you @ATICOSEGUNDA , I will check Elementor now
Hi guys ! can i ask here how to allow upload mutliple file in field upload ultimate member please??
thanks in advance.
How can I change the directory of profile photos from "wp-content/uploads/ultimatemember "file to wordpress media library during uploading. So that I can use those image later on directly taking from media.
I added this code for uploading profile image during registration. Everything is working fine.
function um_get_avatar_uri( $image, $attrs ) {
$uri = false;
$uri_common = false;
$find = false;
$ext = '.' . pathinfo( $image, PATHINFO_EXTENSION );
$custom_profile_photo = get_user_meta(um_user( 'ID' ), 'profile_photo', 'true');
if ( is_multisite() ) {
//multisite fix for old customers
$multisite_fix_dir = UM()->uploader()->get_upload_base_dir();
$multisite_fix_url = UM()->uploader()->get_upload_base_url();
$multisite_fix_dir = str_replace( DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . get_current_blog_id() . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $multisite_fix_dir );
$multisite_fix_url = str_replace( '/sites/' . get_current_blog_id() . '/', '/', $multisite_fix_url );
if ( $attrs == 'original' && file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo{$ext}";
} elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$attrs}x{$attrs}{$ext}";
} elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$attrs}{$ext}";
} else {
$sizes = UM()->options()->get( 'photo_thumb_sizes' );
if ( is_array( $sizes ) ) {
$find = um_closest_num( $sizes, $attrs );
}
if ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}x{$find}{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$find}x{$find}{$ext}";
} elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}";
} elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo{$ext}";
}
}
}
if ( $attrs == 'original' && file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . "/profile_photo{$ext}";
} elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $custom_profile_photo ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $custom_profile_photo;
} elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$attrs}x{$attrs}{$ext}";
} elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$attrs}{$ext}";
} else {
$sizes = UM()->options()->get( 'photo_thumb_sizes' );
if ( is_array( $sizes ) ) {
$find = um_closest_num( $sizes, $attrs );
}
if ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}x{$find}{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$find}x{$find}{$ext}";
} elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}";
} elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo{$ext}";
}
}
if ( ! empty( $uri_common ) && empty( $uri ) ) {
$uri = $uri_common;
}
$cache_time = apply_filters( 'um_filter_avatar_cache_time', current_time( 'timestamp' ), um_user( 'ID' ) );
if ( ! empty( $cache_time ) ) {
$uri .= "?{$cache_time}";
}
return $uri;
}
/**
EXTRA ULTIMATE MEMBER
*/
add_action('um_after_account_general', 'showExtraFields', 100);
function showExtraFields()
{
//these are the meta fields created in registration field
$custom_fields = [
"c_user_contry" => "Country",
"c_complete_address" => "Complete Address",
"c_cnic" => " CNIC (If Pakistani)",
"f_profile_fiverr" => "Fiverr Link",
"f_profile_upwork" => "Upwork Link",
"f_profile_guru" => "Guru Link",
"f_profile_freelancer" => "Freelancer Link",
"f_profile_pph" => "PeoplePerHour Link",
"sp_fb" => "Facebook",
"sp_tw" => "Twitter",
"sp_li" => "LinkedIn",
"sp_yt" => "YouTube",
"sp_gh" => "Github",
"sp_ig" => "Instagram",
];
foreach ($custom_fields as $key => $value) {
$fields[ $key ] = array(
'title' => $value,
'metakey' => $key,
'type' => 'select',
'label' => $value,
);
apply_filters('um_account_secure_fields', $fields, 'wall_privacy' );
$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;
}
}
//action to update values of custom field
add_action( 'um_account_pre_update_profile', 'my_account_pre_update_profile', 10, 2 );
function my_account_pre_update_profile( $changes, $user_id ) {
update_user_meta( $user_id, 'c_user_contry', $_POST['c_user_contry'] );
update_user_meta( $user_id, 'c_complete_address', $_POST['c_complete_address'] );
update_user_meta( $user_id, 'c_cnic', $_POST['c_cnic'] );
update_user_meta( $user_id, 'f_profile_fiverr', $_POST['f_profile_fiverr'] );
update_user_meta( $user_id, 'f_profile_upwork', $_POST['f_profile_upwork'] );
update_user_meta( $user_id, 'f_profile_guru', $_POST['f_profile_guru'] );
update_user_meta( $user_id, 'f_profile_freelancer', $_POST['f_profile_freelancer'] );
update_user_meta( $user_id, 'f_profile_pph', $_POST['f_profile_pph'] );
update_user_meta( $user_id, 'sp_fb', $_POST['sp_fb'] );
update_user_meta( $user_id, 'sp_tw', $_POST['sp_tw'] );
update_user_meta( $user_id, 'sp_li', $_POST['sp_li'] );
update_user_meta( $user_id, 'sp_yt', $_POST['sp_yt'] );
update_user_meta( $user_id, 'sp_gh', $_POST['sp_gh'] );
update_user_meta( $user_id, 'sp_ig', $_POST['sp_ig'] );
}
/**
CODE FOR VIEWING "Extra profile information" AREA IN YOUR USERS BACK-END, MATCH IT WITH YOUR CUSTOM NAMES
*/
function mysite_custom_define() {
$custom_meta_fields = array();
$custom_meta_fields['c_user_contry'] = 'Country';
$custom_meta_fields['c_complete_address'] = 'Complete Address';
$custom_meta_fields['c_cnic'] = 'CNIC (If Pakistani)';
$custom_meta_fields['f_profile_fiverr'] = 'Fiverr Link';
$custom_meta_fields['f_profile_upwork'] = 'Upwork Link';
$custom_meta_fields['f_profile_guru'] = 'Guru Link';
$custom_meta_fields['f_profile_freelancer'] = 'Freelancer Link';
$custom_meta_fields['f_profile_pph'] = 'PeoplePerHour Link';
$custom_meta_fields['sp_fb'] = 'Facebook';
$custom_meta_fields['sp_tw'] = 'Twitter';
$custom_meta_fields['sp_li'] = 'LinkedIn';
$custom_meta_fields['sp_yt'] = 'YouTube';
$custom_meta_fields['sp_gh'] = 'Github';
$custom_meta_fields['sp_ig'] = 'Instagram';
return $custom_meta_fields;
}
function mysite_columns($defaults) {
$meta_number = 0;
$custom_meta_fields = mysite_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
$defaults[('mysite-usercolumn-' . $meta_number . '')] = __($meta_disp_name, 'user-column');
}
return $defaults;
}
function mysite_custom_columns($value, $column_name, $id) {
$meta_number = 0;
$custom_meta_fields = mysite_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
if( $column_name == ('mysite-usercolumn-' . $meta_number . '') ) {
return get_the_author_meta($meta_field_name, $id );
}
}
}
function mysite_show_extra_profile_fields($user) {
print('
Extra profile information
');
print('');
$meta_number = 0;
$custom_meta_fields = mysite_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
print('');
print('');
print('');
print('');
}
print('
' . $meta_disp_name . ' ');
print('
');
print('');
print('
');
}
function mysite_save_extra_profile_fields($user_id) {
if (!current_user_can('edit_user', $user_id))
return false;
$meta_number = 0;
$custom_meta_fields = mysite_custom_define();
foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
$meta_number++;
update_usermeta( $user_id, $meta_field_name, $_POST[$meta_field_name] );
}
}
add_action('show_user_profile', 'mysite_show_extra_profile_fields');
add_action('edit_user_profile', 'mysite_show_extra_profile_fields');
add_action('personal_options_update', 'mysite_save_extra_profile_fields');
add_action('edit_user_profile_update', 'mysite_save_extra_profile_fields');
add_action('manage_users_custom_column', 'mysite_custom_columns', 15, 3);
add_filter('manage_users_columns', 'mysite_columns', 15, 1);
Is anyone can help me to place a validation in myaccount while updating customized fields
to view&update custom fields in the [ultimatemember_account] page, this is some distilled code from here, to be added to your theme's functions.php:
add_action('um_after_account_general', 'showUMExtraFields', 100); function showUMExtraFields() { $id = um_user('ID'); $output = ''; $names = array('phone_number', 'company'); $fields = array(); foreach( $names as $name ) $fields[ $name ] = UM()->builtin()->get_specific_field( $name ); $fields = apply_filters('um_account_secure_fields', $fields, $id); foreach( $fields as $key => $data ) $output .= UM()->fields()->edit_field( $key, $data ); echo $output; } add_action('um_account_pre_update_profile', 'getUMFormData', 100); function getUMFormData(){ $id = um_user('ID'); $names = array('phone_number', 'company'); foreach( $names as $name ) update_user_meta( $id, $name, $_POST[$name] ); }
tested with 2.0.13
How would one use this code to display the custom fields after another specific field (such as after the Username field in the Account tab), as well as make the custom fields uneditable? (Similar to the Username field in the account tab)
This one works good, thanks!
`<?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;
}
}`
Hello
I don't know if this is the right tutorial for displaying custom fields.
My problem is that when I want to display the predefined field "user_mail", it displays nothing. I don't have an email address, as you know, you need one to register, but it works.
How do I display it?
Mz
/** EXTRA ULTIMATE MEMBER */ add_action('um_after_account_general', 'showExtraFields', 100); function showExtraFields() { //these are the meta fields created in registration field $custom_fields = [ "c_user_contry" => "Country", "c_complete_address" => "Complete Address", "c_cnic" => " CNIC (If Pakistani)", "f_profile_fiverr" => "Fiverr Link", "f_profile_upwork" => "Upwork Link", "f_profile_guru" => "Guru Link", "f_profile_freelancer" => "Freelancer Link", "f_profile_pph" => "PeoplePerHour Link", "sp_fb" => "Facebook", "sp_tw" => "Twitter", "sp_li" => "LinkedIn", "sp_yt" => "YouTube", "sp_gh" => "Github", "sp_ig" => "Instagram", ]; foreach ($custom_fields as $key => $value) { $fields[ $key ] = array( 'title' => $value, 'metakey' => $key, 'type' => 'select', 'label' => $value, ); apply_filters('um_account_secure_fields', $fields, 'wall_privacy' ); $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; } } //action to update values of custom field add_action( 'um_account_pre_update_profile', 'my_account_pre_update_profile', 10, 2 ); function my_account_pre_update_profile( $changes, $user_id ) { update_user_meta( $user_id, 'c_user_contry', $_POST['c_user_contry'] ); update_user_meta( $user_id, 'c_complete_address', $_POST['c_complete_address'] ); update_user_meta( $user_id, 'c_cnic', $_POST['c_cnic'] ); update_user_meta( $user_id, 'f_profile_fiverr', $_POST['f_profile_fiverr'] ); update_user_meta( $user_id, 'f_profile_upwork', $_POST['f_profile_upwork'] ); update_user_meta( $user_id, 'f_profile_guru', $_POST['f_profile_guru'] ); update_user_meta( $user_id, 'f_profile_freelancer', $_POST['f_profile_freelancer'] ); update_user_meta( $user_id, 'f_profile_pph', $_POST['f_profile_pph'] ); update_user_meta( $user_id, 'sp_fb', $_POST['sp_fb'] ); update_user_meta( $user_id, 'sp_tw', $_POST['sp_tw'] ); update_user_meta( $user_id, 'sp_li', $_POST['sp_li'] ); update_user_meta( $user_id, 'sp_yt', $_POST['sp_yt'] ); update_user_meta( $user_id, 'sp_gh', $_POST['sp_gh'] ); update_user_meta( $user_id, 'sp_ig', $_POST['sp_ig'] ); } /** CODE FOR VIEWING "Extra profile information" AREA IN YOUR USERS BACK-END, MATCH IT WITH YOUR CUSTOM NAMES */ function mysite_custom_define() { $custom_meta_fields = array(); $custom_meta_fields['c_user_contry'] = 'Country'; $custom_meta_fields['c_complete_address'] = 'Complete Address'; $custom_meta_fields['c_cnic'] = 'CNIC (If Pakistani)'; $custom_meta_fields['f_profile_fiverr'] = 'Fiverr Link'; $custom_meta_fields['f_profile_upwork'] = 'Upwork Link'; $custom_meta_fields['f_profile_guru'] = 'Guru Link'; $custom_meta_fields['f_profile_freelancer'] = 'Freelancer Link'; $custom_meta_fields['f_profile_pph'] = 'PeoplePerHour Link'; $custom_meta_fields['sp_fb'] = 'Facebook'; $custom_meta_fields['sp_tw'] = 'Twitter'; $custom_meta_fields['sp_li'] = 'LinkedIn'; $custom_meta_fields['sp_yt'] = 'YouTube'; $custom_meta_fields['sp_gh'] = 'Github'; $custom_meta_fields['sp_ig'] = 'Instagram'; return $custom_meta_fields; } function mysite_columns($defaults) { $meta_number = 0; $custom_meta_fields = mysite_custom_define(); foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) { $meta_number++; $defaults[('mysite-usercolumn-' . $meta_number . '')] = __($meta_disp_name, 'user-column'); } return $defaults; } function mysite_custom_columns($value, $column_name, $id) { $meta_number = 0; $custom_meta_fields = mysite_custom_define(); foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) { $meta_number++; if( $column_name == ('mysite-usercolumn-' . $meta_number . '') ) { return get_the_author_meta($meta_field_name, $id ); } } } function mysite_show_extra_profile_fields($user) { print(' Extra profile information '); print(''); $meta_number = 0; $custom_meta_fields = mysite_custom_define(); foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) { $meta_number++; print(''); print(''); print(''); print(''); } print(' ' . $meta_disp_name . ' '); print(' '); print(''); print(' '); } function mysite_save_extra_profile_fields($user_id) { if (!current_user_can('edit_user', $user_id)) return false; $meta_number = 0; $custom_meta_fields = mysite_custom_define(); foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) { $meta_number++; update_usermeta( $user_id, $meta_field_name, $_POST[$meta_field_name] ); } } add_action('show_user_profile', 'mysite_show_extra_profile_fields'); add_action('edit_user_profile', 'mysite_show_extra_profile_fields'); add_action('personal_options_update', 'mysite_save_extra_profile_fields'); add_action('edit_user_profile_update', 'mysite_save_extra_profile_fields'); add_action('manage_users_custom_column', 'mysite_custom_columns', 15, 3); add_filter('manage_users_columns', 'mysite_columns', 15, 1);
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!
Hi, how do I add a "woocommerce bookings" tab to my ultimate member account page. Will Woocommerce bookings "booking" work if php is included directly? I really need this.