Skip to content

Instantly share code, notes, and snippets.

@ultimatemember
Last active April 19, 2021 20:35
Show Gist options
  • Save ultimatemember/8cdaf61e7bd9de35512c to your computer and use it in GitHub Desktop.
Save ultimatemember/8cdaf61e7bd9de35512c to your computer and use it in GitHub Desktop.
Extending Ultimate Member Profile Menu using Hooks
/* First we need to extend main profile tabs */
add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 );
function add_custom_profile_tab( $tabs ) {
$tabs['mycustomtab'] = array(
'name' => 'My custom tab',
'icon' => 'um-faicon-comments',
);
return $tabs;
}
/* Then we just have to add content to that tab using this action */
add_action('um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default');
function um_profile_content_mycustomtab_default( $args ) {
echo 'Hello world!';
}
@eminsafa
Copy link

You put this code into your function.php file. Also it is possible to use child themes' functions.php file.

@eminsafa
Copy link

eminsafa commented Jun 13, 2017

By the way you can add one more tab with these codes:

add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 );
function add_custom_profile_tab( $tabs ) {

	$tabs['mycustomtab'] = array(
		'name' => 'Siparişlerim',
		'icon' => 'um-faicon-comments',
	);

	return $tabs;
		
}
/* Then we just have to add content to that tab using this action */

add_action('um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default');
function um_profile_content_mycustomtab_default( $args ) {
	require ("my-orders.php");
}
//----------------------------------------------

add_filter('um_profile_tabs', 'add_custom_profile_tabi', 1000 );
function add_custom_profile_tabi( $tabs ) {

	$tabs['mycustomtab2'] = array(
		'name' => 'My custom tab2',
		'icon' => 'um-faicon-comments',
	);

	return $tabs;
		
}
add_action('um_profile_content_mycustomtab2_default', 'um_profile_content_mycustomtab2_default');
function um_profile_content_mycustomtab2_default( $args ) {
echo "hello";}

@huzanspenta
Copy link

Hi,
In the tab I want to write "Members" and link it to the members page. Can anyone please assist?

@Carlvic
Copy link

Carlvic commented Jul 16, 2017

Hello!

How can I add upload field on my custom tab?

I use this code but it's all blank

`
"/* Finally we add some content in the tab */

add_filter('um_account_content_hook_mytab', 'um_account_content_hook_mytab');
function um_account_content_hook_mytab( $output ){
ob_start();
?>

<div class="um-field">
	
	   <div class="custom-profile-update">
           <?php echo do_shortcode('[ultimatemember form_id=692]'); ?>
	
</div>		
	
<?php
	
$output .= ob_get_contents();
ob_end_clean();
return $output;

}
`

@akblissweb
Copy link

Great examples above but all I would like to do is change the "Posts" tab title to the name of my custom post type "Ratings". I've already got the code to bring in the Ratings. I've searched everywhere and haven't seen any examples of how to change the titles of the existing tabs.
Thanks in advance.

@MvdO79
Copy link

MvdO79 commented Aug 3, 2017

I also need a code example to just change the existing tab names/slugs (Posts,Comments), anyone?

@insaurabh
Copy link

// i am trying to create a custom tab as below

/* First we need to extend main profile tabs */

add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 );
function add_custom_profile_tab( $tabs ) {

$tabs['createevent'] = array(
	'name' => 'Create Event',
	'icon' => 'um-faicon-comments',
);
	
return $tabs;

}

/* Then we just have to add content to that tab using this action */

add_action('um_profile_content_createevent_default', 'um_profile_content_createevent_default');
function um_profile_content_createevent_default( $args ) {
echo do_shortcode( '[custom_short_code id="274"]' );

}

Problem: Tab disappeared as i replaced mycustomtab to createevent ??

@Garconis
Copy link

Garconis commented Dec 1, 2017

Does this still work in version 2.0? I can't get this to work.

@Rajchicken
Copy link

Hi Guys!

Thanks to your comments I have been playing around with the code also but with limited success. I am no developer but at least I was able to add more tabs using the function php file. Now my problem is the following:
I would like my new created tab to redirect to a specific URL.
I have successfully called the tab "Submit Property" but when I click on the tab as a logged in user nothing happens. Can someone supply me with the code in order to redirect the tab to a URL placed outside the plugin please.

I believe i need to make some changes in the last bit of code and add smth like <a href=“URL"> but I am not 100% sure and would appreciate help! Thank you!!

I used this code from "eminsafa" example


add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 );
function add_custom_profile_tab( $tabs ) {

$tabs['mycustomtab'] = array(
	'name' => 'Submit Property',
	'icon' => 'um-faicon-comments',
);

return $tabs;

}
/* Then we just have to add content to that tab using this action */

add_action('um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default');
function um_profile_content_mycustomtab_default( $args ) {
require ("my-orders.php");
}

A BIG THANK YOU
Sabrina

@champsupertramp
Copy link

champsupertramp commented Jul 17, 2018

Hi Everyone,

The code still works in UM 2.0+

You need to turn on the profile tab in WP Admin > Ultimate Member > Settings > Profile Menu.

It is turned off by default.

Regards,

@amponsah
Copy link

Here is the full code to add multiple custom tabs to UM.2.0 - this is put together from the above comments:

/* ------------------------------------------------------------------/
/
CUSTOM TABS /
/
------------------------------------------ ------------------------*/
add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 );
function add_custom_profile_tab( $tabs ) {

// tab1 
$tabs['arrival_info'] = array(
	'name' => 'Arrival Info',
	'icon' => 'um-icon-plane',
);
// tab1 
$tabs['program_summary'] = array(
	'name' => 'Program Summary',
	'icon' => 'um-faicon-bars',
);

return $tabs;

}

// tab1 actions
add_action('um_profile_content_arrival_info', 'um_profile_content_arrival_info_default');
add_action('um_profile_content_program_summary', 'um_profile_content_program_summary_default');

// tab2 actions
add_action('um_profile_content_arrival_info_default', 'um_profile_content_arrival_info_default');
add_action('um_profile_content_program_summary_default', 'um_profile_content_program_summary_default');

function um_profile_content_arrival_info_default ( $args ) {
// add tab1 content - exchange the next line for your own content
echo do_shortcode( '[gravityform id="23" title="false" description="false"]');
}
function um_profile_content_program_summary_default ( $args ) {
// add tab2 content - exchange the next line for your own content
echo do_shortcode( '[uv_um_program_summary]');
}

// THIS GOES IN functions.php
// UM.2.0 - You need to turn on the profile tab in WP Admin > Ultimate Member > Settings > Profile Menu.
// IMPORTANT - You also need to hit save on this page - WP Admin > Ultimate Member > Settings > Profile Menu.

Thanks for all the commenst above.

@gwmbox
Copy link

gwmbox commented Oct 7, 2018

How do I order the default tabs and the two new added tabs in the example code?

@dreaddy
Copy link

dreaddy commented Dec 12, 2018

Just tried it and it was not working for me.
I had to add custom => true:


$tabs['mycustomtab'] = array(
		'name' => 'My custom tab',
		'icon' => 'um-faicon-comments',
                'custom' => true,
	);

@AlfredWest
Copy link

AlfredWest commented Jan 16, 2019

THis seems to work well in basis, but I m having a hard time implementing it the way I would like to.

What I would like to do is to output various profile fields in the tab window.
I have tried to add an ultimate member profile form short code so that I can use the form to display the values that I want to show on the tab. THis does not seem to work at all.

On the other hand if I try to display another short code created by wpforms that works fine.
WHy is the [ultimatemember form_id="1173"] short form not working with this while the wpforms shortcode [wpforms id="1120"] does work?

Is there another way to show Ultimate Member profile fields in the created tab?
Even better would be if I was to be able to allow the user to edit what information showed in the tab, choosing which profile fields would show .

Here is what I have in there now:

// BEGIN ADD PROFILE TABS
/* First we need to extend main profile tabs */

add_filter('um_profile_tabs', 'add_custom_profile_tab', 1000 );
function add_custom_profile_tab( $tabs ) {

$tabs['mycustomtab'] = array(
	'name' => 'My custom tab',
	'icon' => 'um-faicon-comments',
    'custom' => true,
);

return $tabs;

}

/* Then we just have to add content to that tab using this action */

add_action('um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default');
function um_profile_content_mycustomtab_default( $args ) {
echo do_shortcode('[ultimatemember form_id="1173"]');
}
// END ADD PROFILE TABS

@inversi
Copy link

inversi commented Jun 19, 2019

Hello,

I need just to add some links (like a Edit, LogOut) in Member Profile Menu. Can you help me please?
Screen Shot 2019-06-19 at 22 58 28

@nikitasinelnikov
Copy link

Hi there,

Since 2.0.53 version we support Profile Tabs privacy settings for all tabs and 'custom' attribute for custom tabs is deprecated. Instead of this, you could set default privacy for your custom tab. So after the adding of profile tabs, please update your Profile Tabs privacy settings here UM->Settings->Appearances->Profile Menu https://www.screencast.com/t/n2q7MQDoplg

This code still works

// Filter
function um_mycustomtab_add_tab( $tabs ) {
$tabs['mycustomtab'] = array(
'name' => 'My Custom',
'icon' => 'um-faicon-pencil',
);
return $tabs;
}
add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 );

// Action
function um_profile_content_mycustomtab_default( $args ) {
echo 'Hello world!';
}
add_action( 'um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default' );

Thanks!

@rajb686
Copy link

rajb686 commented Sep 8, 2019

thanks @nikitasinelnikov

where exactly do we add these lines of code?

@nikitasinelnikov
Copy link

hi @rajb686

You could add these lines in your theme or child-theme. Also, you may create your own plugin with all custom solutions at your site and paste these code lines in this plugin.

I recommend inserting these lines to child-theme.

Thanks!

@dbjpanda
Copy link

dbjpanda commented Sep 21, 2019

The one which works.

// Filter
function um_add_custom_tabs( $tabs ) {
    $tabs['account'] = array(
        'name' => 'Edit Account',
        'icon' => 'um-faicon-pencil',
        'custom' => TRUE
    );

    $tabs['profile'] = array(
        'name' => 'Edit Profile',
        'icon' => 'um-faicon-pencil',
        'custom' => TRUE
    );

    return $tabs;
}
add_filter( 'um_profile_tabs', 'um_add_custom_tabs', 1000 );

// Action
function um_profile_content_edit_account_default( $args ) {
    echo do_shortcode('[ultimatemember_account]');
}
add_action( 'um_profile_content_account_default', 'um_profile_content_edit_account_default' );


function um_profile_content_profile_default( $args ) {
    wp_redirect( "/user?profiletab=main&um_action=edit" );
}
add_action( 'um_profile_content_profile_default', 'um_profile_content_profile_default' );

@CoachAIng
Copy link

I've got custom tabs added ok, and are now looking at adding content within those tabs. I can add text in using echo, or a shortcode or a re-direct from the code snippets above.

What i'm trying to do is embed a different pre-existing page within the new custom tab, so that it will display there without me having to hard code it into the function.php file.

I think i'm just missing the right syntax to be able to do this?

@hirenshah
Copy link

hirenshah commented Mar 11, 2020

@CoachAlng Did you figure this out? I'm looking to do the same 🙂

@rgravine
Copy link

rgravine commented Mar 27, 2020

Tabs are producing the data I want. In back-end of Ultimate member all functions are working correctly but I'm having an issue with privacy.

I have echoed user roles with:

which are:

um_musician-level-1
um_musician-level-2
um_musician-level-3

I need SOUNDCLOUD and YOUTUBE tab for role = um_musician-level-3

Anyone can see the tab on any profile as long as said profile has role = um_musician-level-3

Level 3 will always have the tab on their profile. Level 1 and 2 should not because they have not paid for it.

I had it working I BELIEVE but got so deep into other coding as you can see below I must have made a typo.

`

/**

  • Add a new SoundCloud Embed Profile tab
    */
    function um_mycustomtab_add_tab( $tabs ) {

    $tabs[ 'mycustomtab' ] = array(
    'name' => 'Sound Cloud',
    'icon' => 'um-faicon-soundcloud',
    'custom' => true,
    'default_privacy' => 0,

    );

// Show to other profiles
if ( is_user_logged_in() && get_current_user_id() != $user_id ) {
$tabs['mycustomtab'] = array(
'name' => 'Sound Cloud',
'icon' => 'fa fa-soundcloud',
'custom' => true
);
}

// Hide from specific roles
$hide_from_roles = array( 'um_musician-level-1','um_musician-level-2' );

if ( is_user_logged_in() && ! in_array( um_user('role') , $hide_from_roles )  ) {
	$tabs['mycustomtab'] = array(
		'name' => 'Sound Cloud',
		'icon' => 'fa fa-soundcloud',
		'custom' => true
	);
}

UM()->options()->options[ 'profile_tab_' . 'mycustomtab' ] = true;

return $tabs;

}
add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 );

// Render Tab Content
function um_profile_content_mycustomtab_default( $args ) {
$action = 'mycustomtab';
$fields_metakey = array('sound_cloud_user_id'

);

$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 ) );
?>
<script> var url = new URL(window.location.href); var query_string = url.search; var search_params = new URLSearchParams(query_string); var sound_cloud_user_id = var iframe = "<iframe height='800px' width='100%' frameborder='0' allowTransparency='true' scrolling='no' src='https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/users/"+sound_cloud_user_id+"&color=%23dc2751&auto_play=true&hide_related=false&show_comments=false&show_user=true&show_reposts=false&show_teaser=false'></iframe>"; document.write(iframe ); </script>
</div>

<?php

}
add_action( 'um_profile_content_mycustomtab_default', 'um_profile_content_mycustomtab_default' );

/**

  • Add a new YouTube Channel Embed Profile tab
    */
    function um_myyoutubetab_add_tab( $tabs ) {

    $tabs[ 'myyoutubetab' ] = array(
    'name' => 'YouTube',
    'icon' => 'um-faicon-yotube',
    'custom' => true,
    'default_privacy' => 0,

    );

// Show to other profiles
if ( is_user_logged_in() && get_current_user_id() != $user_id ) {
$tabs['myyoutubetab'] = array(
'name' => 'YouTube',
'icon' => 'fa fa-youtube',
'custom' => true
);
}

// Hide from specific roles
$hide_from_roles = array( 'um_musician-level-1','um_musician-level-2' );

if ( is_user_logged_in() && ! in_array( um_user('role') , $hide_from_roles )  ) {
	$tabs['myyoutubetab'] = array(
		'name' => 'Youtube',
		'icon' => 'fa fa-youtube',
		'custom' => true
	);
}

UM()->options()->options[ 'profile_tab_' . 'myyoutubetab' ] = true;

return $tabs;

}
add_filter( 'um_profile_tabs', 'um_myyoutubetab_add_tab', 1000 );

// Render Tab Content
function um_profile_content_myyoutubetab_default( $args ) {
$action = 'myyoutubetab';
$fields_metakey = array('youtube_channel_id'

);

$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>

<?php

}
add_action( 'um_profile_content_myyoutubetab_default', 'um_profile_content_myyoutubetab_default' );

@fasterboy32
Copy link

Hi everyone,
I m unable to complete my task, upload an audio file, and then when I click on it, it is downloadable not playing an audio file what I do
please help me

@moserello
Copy link

moserello commented Feb 16, 2021

I just tried to add a shortcode in a custom tab with the following:

`add_filter('um_account_page_default_tabs_hook', 'add_kd_redeem_tab', 100 );
function add_kd_redeem_tab( $tabs ) {
$tabs[800]['redeem_kd_tab']['icon'] = 'um-icon-ios-world';
$tabs[800]['redeem_kd_tab']['title'] = 'Title';
$tabs[800]['redeem_kd_tab']['custom'] = true;
return $tabs;
}

add_action('um_account_tab__redeem_kd_tab', 'um_account_tab__redeem_kd_tab');
function um_account_tab__redeem_kd_tab( $info ) {
global $ultimatemember;
extract( $info );

$output = $ultimatemember->account->get_tab_output('redeem_kd_tab');
if ( $output ) { echo $output; }

}

add_filter('um_account_content_hook_redeem_kd_tab', 'um_account_content_hook_redeem_kd_tab');
function um_account_content_hook_redeem_kd_tab( $output ){
ob_start();
?>

<div class="um-field">
	
    <?php echo do_shortcode("[mycred_load_coupon label='Insert code here' button='Redeem']"); ?>
    		
</div>		
	
<?php
	
$output .= ob_get_contents();
ob_end_clean();
return $output;

}`

  1. The shortcode displays correctly but when I hit the button I just get a page refresh instead of triggering the button generated by the shortcode
  2. The shortcode works properly if put in the account page, outside tabs

The shortcode that I'm using is here:
https://codex.mycred.me/shortcodes/mycred_load_coupon/

What am I missing?
Thanks in advance!

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