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, 7 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
April 19, 2020 at 6:27 pm #8001
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.
April 20, 2020 at 10:03 am #8011Hi,
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,
PatrikApril 20, 2020 at 11:27 am #8013Thank 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.
April 20, 2020 at 11:58 am #8015Hi,
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,
PatrikApril 20, 2020 at 12:21 pm #8017I 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?
April 20, 2020 at 12:54 pm #8018It’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; }
April 20, 2020 at 2:20 pm #8023Finally, 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.
April 23, 2020 at 10:34 am #8107Hi,
Yes using shortcodes if no predefined tabs are there is a good idea.
Regards,
Patrik -
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket