Skip to content

Instantly share code, notes, and snippets.

@denisbaranov
Last active January 25, 2024 01:16
Show Gist options
  • Save denisbaranov/162fe5c96b65c693651388fdc4a7e08d to your computer and use it in GitHub Desktop.
Save denisbaranov/162fe5c96b65c693651388fdc4a7e08d to your computer and use it in GitHub Desktop.
This example shows how to add a new tab into the Profile page of the Ultimate Member.
<?php
/**
* This example shows how to add a new tab into the Profile page of the Ultimate Member.
* See the article https://docs.ultimatemember.com/article/69-how-do-i-add-my-extra-tabs-to-user-profiles
*
* This example adds the tab 'mycustomtab' that contains the field 'description'. You can add your own tabs and fields.
* Important! Each profile tab has an unique key. Replace 'mycustomtab' to your unique key.
*
* You can add this code to the end of the file functions.php in the active theme (child theme) directory.
*
* Ultimate Member documentation: https://docs.ultimatemember.com/
* Ultimate Member support (for customers): https://ultimatemember.com/support/ticket/
*/
/**
* Add a new Profile tab
*
* @param array $tabs
* @return array
*/
function um_mycustomtab_add_tab( $tabs ) {
$tabs[ 'mycustomtab' ] = array(
'name' => 'My Custom',
'icon' => 'um-faicon-pencil',
'custom' => true
);
UM()->options()->options[ 'profile_tab_' . 'mycustomtab' ] = true;
return $tabs;
}
add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 );
/**
* Render tab content
*
* @param array $args
*/
function um_profile_content_mycustomtab_default( $args ) {
/* START. You can paste your content here, it's just an example. */
$action = 'mycustomtab';
/* List user fields you want to see in this form. */
$fields_metakey = array(
'description'
);
$nonce = filter_input( INPUT_POST, '_wpnonce' );
if( $nonce && wp_verify_nonce( $nonce, $action ) && um_is_myprofile() ) {
foreach( $fields_metakey as $metakey ) {
update_user_meta( um_profile_id(), $metakey, filter_input( INPUT_POST, $metakey ) );
}
UM()->user()->remove_cache( um_profile_id() );
}
$fields = UM()->builtin()->get_specific_fields( implode( ',', $fields_metakey ) );
?>
<div class="um">
<div class="um-form">
<form method="post">
<?php
if( um_is_myprofile() ) {
foreach( $fields as $key => $data ) {
echo UM()->fields()->edit_field( $key, $data );
}
} else {
foreach( $fields as $key => $data ) {
echo UM()->fields()->view_field( $key, $data );
}
}
?>
<?php if( um_is_myprofile() ) : ?>
<div class="um-col-alt">
<div class="um-left">
<?php wp_nonce_field( $action ); ?>
<input type="submit" value="<?php esc_attr_e( 'Update', 'ultimate-member' ); ?>" class="um-button" />
</div>
</div>
<?php endif; ?>
</form>
</div>
</div>
<?php
/* END. You can paste your content here, it's just an example. */
}
add_action( 'um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default' );
@Myron-AN
Copy link

Myron-AN commented Apr 1, 2020

how should I display form in this custom tab? Any form.

@Z1LL10N
Copy link

Z1LL10N commented May 21, 2020

how / where to implement your code please? thanks!!

@sas33
Copy link

sas33 commented May 23, 2020

Please tell us where to implement this

@tushar-cloud
Copy link

Please tell us where to implement this

Add this on your theme function.php

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