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
  • Author
    Posts
  • #1463

    Derek Gallimore
    Buyer
    Post count: 25

    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

    #1465

    Alex Rollin
    Moderator
    Post count: 27815

    Hello,

    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.

    #1466

    Derek Gallimore
    Buyer
    Post count: 25

    Hi 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.

    #1467

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    I have flagged this for patrik who will look at it tomorrow.

    Thanks,

    Stiofan

    #1468

    Patrik
    Moderator
    Post count: 1971

    Hi 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,
    Patrik

    #1469

    Derek Gallimore
    Buyer
    Post count: 25

    Hi 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 – GeoDirectory

    Am I missing something?

    Thank you,
    Derek

    #1470

    Derek Gallimore
    Buyer
    Post count: 25

    Hi 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,
    Derek

    #1472

    Patrik
    Moderator
    Post count: 1971

    Hi 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,
    Patrik

    #1473

    Derek Gallimore
    Buyer
    Post count: 25

    Hi 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.

    #1481

    Patrik
    Moderator
    Post count: 1971

    Hi 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,
    Patrik

    #1484

    Derek Gallimore
    Buyer
    Post count: 25

    Hi Patrik,

    Thank you for the info. I’ll update you if the filter worked in the new update that will be released.

    Best,
    Derek

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

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

Open Support Ticket