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!';
}
@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