s2Member and bp

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

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

Open Support Ticket
  • Author
    Posts
  • #37028

    urbanfix
    Expired Member
    Post count: 310

    I would like to hide the ‘Listings’ tab to some users on my site.
    I have installed s2member and the following code works (for the change avatar sub nav: it displays on level 2 and up);

    <?php
    function bp_remove_nav_item() {
    if(current_user_cannot(“access_s2member_level2”))
    global $bp;

    bp_core_remove_subnav_item( $bp->profile->slug, ‘change-avatar’ );
    }
    add_action( ‘wp’, ‘bp_remove_nav_item’ );
    ?>

    Thus I figured changing the code to;

    <?php
    function bp_remove_nav_item() {
    if(current_user_cannot(“access_s2member_level2”))
    global $bp;

    bp_core_remove_nav_item(‘listings’);
    }
    add_action( ‘wp’, ‘bp_remove_nav_item’ );
    ?>

    But that has hidden the listings tab from all users, any help would be appreciated, I know this is kind of out of the scope of this forum but I have failed to get help anywhere else!
    Thanks

    #37041

    urbanfix
    Expired Member
    Post count: 310

    @guust any ideas?

    #37057

    Guust
    Moderator
    Post count: 29970

    Without testing, what you have implemented should hide the tab of every user, for any other visitor except level 2 and above.
    So anybody with level 2 and above should be able to see the tab of levels 0 to 4.

    Is that what you are trying to do?

    I did not know current_user_cannot existed.
    Can you use current_user_can instead?
    https://codex.wordpress.org/Function_Reference/current_user_can

    #37062

    urbanfix
    Expired Member
    Post count: 310

    Thats what i thought but it didn’t work it hid it from everyone!
    I have 0 PHP/CSS knowledge so I just put together things i found on the interweb haha 🙂
    I got some help from the buddypress forums and the following does exactly what I specified.

    
    
    function urbanfix_remove_nav_item() {
    
       if( current_user_cannot("access_s2member_level2") )
           bp_core_remove_nav_item('listings');
    }
    add_action( 'wp', 'urbanfix_remove_nav_item' );

    as for the cannot term i found it here;
    https://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_current_user_cannot%28%29

    Thats just a work around, as level 2> will still see the tab on a level 0 or 1 profile. Ideally I would only like it on a level 2 profile. If you’ve got any ideas please let me know, or you can mark as resolved! Cheers

    #37063

    Paolo
    Site Admin
    Post count: 31206

    Hi Urbafix,

    as far as I can understand the function works, what is not working is the s2members conditional check.

    I think it would be appropirate to ask for support to s2members author.

    Me for example I’ve never used that plugin, so I can’t really support it.

    Thank you

    #37076

    urbanfix
    Expired Member
    Post count: 310

    Hey Paolo,
    Haha, I found the soloution and posted it 1 minute before you commented!
    Thanks

    #37077

    Paolo
    Site Admin
    Post count: 31206

    we were probably writing at the same time.
    I’ll set this as solved.

    Thanks

Viewing 7 posts - 1 through 7 (of 7 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