Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save champsupertramp/9237eb69b1f76e3b0437b466307f41a2 to your computer and use it in GitHub Desktop.
Save champsupertramp/9237eb69b1f76e3b0437b466307f41a2 to your computer and use it in GitHub Desktop.
Ultimate Member - Hide profile tabs from other user roles
<?php
add_filter('um_profile_tabs', 'pages_tab', 1000 );
function pages_tab( $tabs ) {
$user_id = um_get_requested_user();
// Show to profile owners only
if ( is_user_logged_in() && get_current_user_id() == $user_id ) {
$tabs['faves'] = array(
'name' => 'Faves',
'icon' => 'fa fa-star',
'custom' => true
);
}
// Show to other profiles
if ( is_user_logged_in() && get_current_user_id() != $user_id ) {
$tabs['faves'] = array(
'name' => 'Faves',
'icon' => 'fa fa-star',
'custom' => true
);
}
// Show to everyone
$tabs['faves'] = array(
'name' => 'Faves',
'icon' => 'fa fa-star',
'custom' => true
);
// Hide from specific roles
$hide_from_roles = array( 'teacher','principal' );
if ( is_user_logged_in() && ! in_array( um_user('role') , $hide_from_roles ) ) {
$tabs['faves'] = array(
'name' => 'Faves',
'icon' => 'fa fa-star',
'custom' => true
);
}
return $tabs;
}
?>
@kazakh1979
Copy link

I like to hide "posts" and "comments" tabs on the profile. Can somebody tell me how please.

@champsupertramp
Copy link
Author

Hi @kazakh1979 - go to WP Admin > Ultimate Member > Settings > Profile Menu > uncheck the options "Posts Tab" & "Comments Tab".

Subscribe to my newsletter on my website for more Ultimate Member tips and tricks: www.champ.ninja

Regards,

@Z1LL10N
Copy link

Z1LL10N commented May 21, 2020

@champsupertramp, could you please let us know in detail how we implement your code? thanks a ton in advance.

@stevesole
Copy link

Hiya,

I am trying to get my Silver membership profile menu to only show About, Activity, reviews, friends, forums

My Gold to show About, Activity, reviews, friends, jobs, forums

and my platinum users to show About, Posts, Activity, reviews, friends, jobs, forums

So at present a platinum member looking up a silver member sees all the menu options but I am trying to hide the options a silver or gold member are not supposed to have when viewed by the higher membership levels.

Are you still available for help as I see the last posts are from 2020 ...

@stevesole
Copy link

@champsupertramp, could you please let us know in detail how we implement your code? thanks a ton in advance.

yes please!! :)

@champsupertramp
Copy link
Author

Hi @stevesole

You can check the following example to display
specific tabs to specific roles:

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

	$user_id = um_get_requested_user();
       $all_tabs = $tabs;

	// Show to specific roles
	$show_for_roles = array( 'silver-member','bronze-silver' );

	if ( is_user_logged_in() && in_array( um_user('role') , $hide_from_roles )  ) {

               unset( $tabs ); // Disable all tabs
               // Show tabs
	       $tabs['main'] = $all_tabs['main']; 
               $tabs['posts'] = $all_tabs['posts']; 
               $tabs['activity'] = $all_tabs['activity']; 
	}
	
	return $tabs;
}

@stevesole
Copy link

stevesole commented Oct 10, 2022

Hi @champsupertramp

Thank you for that..

How much do you charge to help with PHP?

I am trying to get some tabs only seen by the owner and friends...

And some tags like About (which doesn´t need to be shown to the owner as thats their profile)

I am just trying to cut down tabs as it looks messy on the mobile with too many there.

How do I do that?

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