Skip to:
Content
Pages
Categories
Search
Top
Bottom

Private forum index and forums


  • BenM
    Participant

    @alysko

    Hi,

    I would like to add private forums. So I set my forums to private and I create a private page with [bbp-forum-index] shortcode (slug of this page is ‘forums’). After this, I add the forum page to my top menu.

    But nothing works for guest visitors :
    – I see the forum page in menu even if I’m not logged in.
    – If I’m not logged in and I click on forum page, I’ve a 404.

    If user is logged, it works.

    What’s the problem ? How can I hide menu item to non-logged users ?

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)

  • joym
    Participant

    @joymoleta

    You can try the nav menu roles plugin. It works well as long as it’s compatible with your theme.


    BenM
    Participant

    @alysko

    In fact, I prefered to do iy myself. It’s not specific to bbpress and I’m very surprised that WP doesn’t have this feature natively.

    For the ones who nedd this, here is my simple code :

    function yournamespace_exclude_menu_items( $items, $menu, $args ) {
        // only hide items in front, not admin
        if ( !is_admin() ) {
        // Iterate over the items
        foreach ( $items as $key => $item ) {
          // hide menu items which leads to pages with 'private' status
          if ( !is_user_logged_in() && get_post_status($item->object_id) == 'private' ) unset( $items[$key] );
        }
        return $items;
      }
      else return $items;
    }
    
    add_filter( 'wp_get_nav_menu_items', 'yournamespace_exclude_menu_items', null, 3 );

    Robin W
    Moderator

    @robin-w

    Thanks for sharing !

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar