RE: hide-listing-tab-if-no-listings-owned
This topic contains 10 replies, has 4 voices, and was last updated by Derek Gallimore 6 years, 9 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
February 2, 2018 at 1:15 pm #1463
I want to hide listing tab if no listing owned or created.
I saw this topic related to my issue.
https://userswp.io/support/topic/hide-listing-tab-if-no-listings-owned/Do you already have workaround or snippet/hook regarding this matter?
Best
February 2, 2018 at 1:22 pm #1465Hello,
there was no workaround as yet, however, we are hard at work on the next version which will be released very soon, and I will flag this for the developers in case they have more information to share at this time.
February 2, 2018 at 1:36 pm #1466Hi Alex,
Thank you for your hardwork. Yeah, maybe some guideline on how to achieve this feature, a filter/hook that I can look and work into.
February 2, 2018 at 2:35 pm #1467I have flagged this for patrik who will look at it tomorrow.
Thanks,
Stiofan
February 3, 2018 at 6:13 am #1468Hi Derek,
Please put following code in functions.php file of your currently active theme and let me know if it works for you.
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; }
This code will hide listings, reviews, favorites and invoices tabs if there are no any count. You can modify the code as per your requirements.
Let me know if any queries.
Regards,
PatrikFebruary 3, 2018 at 8:39 am #1469Hi Patrik,
I put the filter function on my child theme and I encountered this fatal error:
Uncaught Error: Class ‘UsersWP_GeoDirectory_Plugin’ not found in ../public_html/wp-content/themes/my-theme-child/functions.php:1288
It seems like this line of code is not working.
$uwp_gd = UsersWP_GeoDirectory_Plugin::get_instance();I have these plugins installed:
GeoDirectory
GeoDirectory Advance Search Filters
GeoDirectory Custom Post Types
GeoDirectory Location Manager
UsersWP
UsersWP – GeoDirectoryAm I missing something?
Thank you,
DerekFebruary 3, 2018 at 8:55 am #1470Hi Patrik,
I attached an image.
Will the companies tab be hidden with the filter you provided?
I want all the tabs under listings be hidden if has no post count.Best,
DerekFebruary 3, 2018 at 10:07 am #1472Hi Derek,
The code I have provided will hide the main listing tabs if no any listings found. For subtabs, we need to make a change in core file to allow access to $type parameter in the filter. If you would like to make a change in core then you can put following code in functions.php file:
add_filter('uwp_profile_gd_tabs', 'uwp_remove_profile_gd_subtabs', 99, 3); function uwp_remove_profile_gd_subtabs($tabs, $user, $type){ $gd_post_types = geodir_get_posttypes('array'); if (empty($gd_post_types)) { return $tabs; } // allowed post types if ($type == 'listings') { $listing_post_types = uwp_get_option('gd_profile_listings', array()); } elseif ($type == 'reviews') { $listing_post_types = uwp_get_option('gd_profile_reviews', array()); } elseif ($type == 'favorites') { $listing_post_types = uwp_get_option('gd_profile_favorites', array()); } else { $listing_post_types = array(); } if (!is_array($listing_post_types)) { $listing_post_types = array(); } foreach ($listing_post_types as $post_type) { if (array_key_exists($post_type, $gd_post_types)) { $post_type_slug = $gd_post_types[$post_type]['has_archive']; if ($type == 'listings') { $count = uwp_post_count($user->ID, $post_type); } elseif ($type == 'reviews') { $count = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, true); } elseif ($type == 'favorites') { $count = $this->geodir_count_favorite($post_type, $user->ID); } else { $count = 0; } if (empty($count)) { unset($tabs[$post_type_slug]); } } } return $tabs; }
Also, Make following change in core file of plugin located at userswp/includes/libraries/class-geodirectory-plugin.php at line no. 565
return apply_filters('uwp_profile_gd_tabs', $tabs, $user, $type);
The class UsersWP_GeoDirectory_Plugin is defined in class-geodirectory-plugin.php located in plugin userswp/includes/libraries/ folder and it’s a part of core plugin.
If possible please provide us the FTP details in private reply so that I can look more into that and do this for you.
Regards,
PatrikFebruary 3, 2018 at 10:51 am #1473Hi Patrik,
It seems like the libraries folder is not existing in userswp plugin directory. Screenshot attached.
I’m using the latest UsersWP plugin version 1.0.11
Thank you,
Derek.February 3, 2018 at 12:39 pm #1481Hi Derek,
I would request you to wait for the next release of the plugin as it will contain the library folder and you can then use the above codes for hiding listings if no listings. The next release will be very soon!
Regards,
PatrikFebruary 3, 2018 at 12:50 pm #1484Hi Patrik,
Thank you for the info. I’ll update you if the filter worked in the new update that will be released.
Best,
Derek -
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket