Custom field fieldset tabs – gd_tab and number – can we do name?

This topic contains 4 replies, has 3 voices, and was last updated by  jahusdtc 6 years, 7 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #429223

    jahusdtc
    Expired Member
    Post count: 162

    I know about css selector on a custom field fieldset. #gd_tab_1, etc.

    I SEEM to be running into a sticky situation where I am trying to say a particular tab is only visible to a certain user.

    I have several fieldsets (tabs in Detail page) that appear or disappear depending on user and price package.

    Situation: In GeoDir>Place Settings, I added several custom fieldsets with custom fields within them. I cannot add class to fieldset, but CAN add class to custom fields. These fieldsets will appear as tabs on Detail page.

    Say I have the following example fieldsets:
    Coupon fieldset
    Video fieldset
    My Info fieldset.

    The Coupon and Video fieldsets only appear if there’s something in them…and if they’re included in particular package.

    The My Info fieldset only appears if I’m the user.

    What I realized is…(I think) the gd_tab number may change depending on what tabs are allowed to be active. Therefore my rather critical css is not being applied properly.

    So, I may use CSS and my numbered selector to do something to gd_tab_1 this time…and it’s a different tab number next time.

    How can I add a tab class, so IF that tab is available, the tab CLASS will always be the same? And therefore I can reliably target with my css selector?

    Any ideas?

    #429228

    Alex Rollin
    Moderator
    Post count: 27815
    This reply has been marked as private.
    #429233

    jahusdtc
    Expired Member
    Post count: 162
    This reply has been marked as private.
    #429336

    Kiran
    Moderator
    Post count: 7069

    Hello,

    Use following code snippet. It will assign unique id to each fieldset tab.

    
    
    function _gd_custom_tab_fieldset_class( $tabs ) {
    	$new_tabs = array();
    	foreach ( $tabs as $key => $tab ) {
    		if ( strpos( $key, 'gd_tab_' ) === 0 ) {
    			$tab_id = 'gd_tab_' . sanitize_html_class( $tab['heading_text'] );
    		} else {
    			$tab_id = $key;
    		}
    		$new_tabs[ $tab_id ] = $tab;
    	}
    	return $new_tabs;
    }
    add_filter( 'geodir_detail_page_tab_list_extend', '_gd_custom_tab_fieldset_class', 9999, 1 );

    The tab id generated based on fieldset title. Ex: if field set title is “Contact Info” then tab id will be “gd_tab_ContactInfo”. Now you can use add style for specific that tab like
    #gd_tab_ContactInfo {
    // yous style here
    }

    Thanks,
    Kiran

    #429553

    jahusdtc
    Expired Member
    Post count: 162

    Kiran, yes, it is solved and resolved.

    What an elegant piece of code. 10 lines!
    Gotta tell you you would have been appalled at what I was trying to use to solve the problem. Your solution was masterful.

    Just drop in and it works. Love it!

    Really, this should be in the “popular things people might want to do” section of the documentation.

    Just a quick suggestion, if someone drops in this code and some other part “appears” not to work.

    It probably is in that sneaky third parameter of add_filter.

    I had exclude tabs working on same filter, according to Guust’s (also clever) code here:
    From <https://wpgeodirectory.com/support/topic/i-want-to-restrict-s2-member-access-to-a-specific-tab/#post-427397&gt;

    Exclusion “appeared” to stop working because I was assessing $tab name with the NEW tab name…but I had the priority set to trigger BEFORE your code had processed.

    Once I made your priority just slightly before the exclude priority, it worked fine. (Exclude became 9999, yours became 9998).

    Really a clever bit of code. Thank you very much!

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

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

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount