-
-
Save ultimatemember/8cdaf61e7bd9de35512c to your computer and use it in GitHub Desktop.
/* 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!'; | |
} |
Does this still work in version 2.0? I can't get this to work.
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
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,
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.
How do I order the default tabs and the two new added tabs in the example code?
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,
);
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
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!
thanks @nikitasinelnikov
where exactly do we add these lines of code?
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!
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' );
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?
@CoachAlng Did you figure this out? I'm looking to do the same 🙂
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 ) );
?>
</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' );
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
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;
}`
- 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
- 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!
// 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 ) {
}
/* 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 ??