I don't found the option to hide empty tabs

This topic contains 7 replies, has 2 voices, and was last updated by  Patrik 4 years ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #8001

    Brigitte
    Expired Member
    Post count: 235

    Bonsoir,

    I did a search on the forum, and I wanted to use the nice snippet proposed by Patrik to remove the tabs without content.

    Until I read that Patrik was doing an update for this feature, see here: https://userswp.io/support/topic/re-hide-listing-tab-if-no-listings-owned/#post-1481

    But I can’t find the option in UsersWP settings.

    Thank you for your help.

    #8011

    Patrik
    Moderator
    Post count: 1971

    Hi,

    We have changed multiple things after that. We have added a tab builder to add/remove tabs in the profile. By default, tabs will be hidden if there is no content in the tab. You can override the templates if it is displaying a message like “No listings found”. You can remove this message from the template you have override and it will display no content for tab and due to no content in the tab, the tab will be not displayed.

    Regards,
    Patrik

    #8013

    Brigitte
    Expired Member
    Post count: 235

    Thank you for your clear answer Patrik.

    But I need more details please. My theme uses the same template (profile-tabs.php) as the original UsersWP file (except some CSS changes).

    Unfortunately I tried to delete the content of the tab content in the php file, But all the tabs still appear …

    Here is the code whose content I have deleted. It is not clear how UsersWP checks if there is content or not, should I delete the div? Only its content?

    
    
    <div id="tab-content" class="container uwp-profile-content">
    	<?php
    	if(!empty($tabs_array)) {
    		foreach ($tabs_array as $tab) {
    			$tab_id = $tab['tab_key'];
    			$tab_url = uwp_build_profile_tab_url($user->ID, $tab_id, false);
    
    			$active = $active_tab == $tab_id ? ' active' : '';
    
    			if ($active_tab == $tab_id) {
    				$active_tab_content = $tab['tab_content_rendered'];
    			}
    
    		}
    	}
    	?>
    	<div class="uwp-profile-entries">
    		<?php
    		if(isset($active_tab_content) && !empty($active_tab_content)){
    			echo $active_tab_content;
    		}
    		?>
    	</div>
    </div>

    Thanks for your help.

    #8015

    Patrik
    Moderator
    Post count: 1971

    Hi,

    Yes, there should be no output like blank div or any other tag. Also, you should not modify this file as this file is responsible for outputting the tab links and contents of the respective tabs. You will need to modify those template files which display the actual content like for example “loop-posts.php” which is responsible for outputting posts and comments in tabs. You can modify this file so that it doesn’t output any single word of content not even HTML tags.

    Regards,
    Patrik

    #8017

    Brigitte
    Expired Member
    Post count: 235

    I sincerely apologize Patrik but I don’t understand. Are you sure we are talking about the same thing?

    I just want the tabs to disappear if there is no content (instead of a message saying that there is no content. Besides this would also solve my second current problem here:

    We must differentiate the predefined tabs (posts, comments,) with the custom tabs.

    Indeed with the custom tabs, if we leave the tab content field empty, the tab disappears. But that doesn’t really make sense because the purpose of a custom field is to add a shortcode to it.

    But for the moment my interest here is to make a predefined tab disappear as long as it has no content.

    What do you think?

    #8018

    Brigitte
    Expired Member
    Post count: 235

    It’s a shame because this snippet seemed so interesting and easy to use:

    add_filter('uwp_profile_tabs', 'uwp_remove_profile_gd_tabs', 99, 2);
    function uwp_remove_profile_gd_tabs($tabs, $user){
        $uwp_gd = UsersWP_GeoDirectory_Plugin::get_instance();
    
        // Hide listing tab if no listings
        $l_count = $uwp_gd->get_total_listings_count($user->ID);
        if($l_count <= 0){
            unset($tabs['listings']);
        }
    
        // Hide reviews tab if no listings
        $r_count = $uwp_gd->get_total_reviews_count($user->ID);
        if($r_count <= 0){
            unset($tabs['reviews']);
        }
    
        // Hide favourites tab if no listings
        $f_count = $uwp_gd->get_total_favorites_count($user->ID);
        if($f_count <= 0){
            unset($tabs['favorites']);
        }
    
        // Hide invoices tab if no listings
        if(class_exists('WPInv_Invoice')){
            $i_count = $uwp_gd->invoice_count($user->ID);
            if($i_count <= 0){
                unset($tabs['invoices']);
            }
        }
    
        return $tabs;
    }
    #8023

    Brigitte
    Expired Member
    Post count: 235

    Finally, if all of this is complicated or important to benefit any next updates, the simplest is that I ONLY use custom tabs and NO predefined tabs. I can easily create shortcodes. Is it a better idea? Thank you.

    #8107

    Patrik
    Moderator
    Post count: 1971

    Hi,

    Yes using shortcodes if no predefined tabs are there is a good idea.

    Regards,
    Patrik

Viewing 8 posts - 1 through 8 (of 8 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket